2015-01-09 87 views
0

我需要写一个<link rel="canonical" href="www.website.com/CURRENT_PATH"/>。我在下面的代码中获得了一半,但我错过了路由器中的翻译。 CURRENT_PATH如何反映网址?在ApplicationController中余烬路线名称照顾路径

当前代码:

setCanonicalURL: function() { 
    'use strict'; 

    $('head link[rel="canonical"]').attr("href", "http://website.com/" + this.get('currentRouteName')); 
    }.observes('currentRouteName'), 

这给了我http://website.com/search.index,而我希望它是http://website.com/products/index

我的路由器包含:

this.resource('search', { path: '/products'} , function(){ 
    this.route('index'); 

回答

0

优雅简约的中底:

App.ApplicationController = Ember.Controller.extend({ 

    setCanonicalURL: function() { 
    'use strict'; 

    $('head link[rel="canonical"]').attr("href", "http://website.com" + this.get('target.url')); 
    }.observes('target.url') 
}); 
0

尝试:

this.get('currentPath').replace(/\./g,'/'); 

代替:

this.get('currentRouteName'); 
+0

最重要的这里是“重命名”,随着路由器的路径出现。 currentPath和currentRoute都返回search.index – Rudi 2015-01-10 15:45:03