Ember.js 负责路径的余烬路径名称
我需要写一封信。下面的代码我已经写了一半了,但是我错过了路由器中的翻译。当前路径如何反映url ApplicationController中的当前代码:Ember.js 负责路径的余烬路径名称,ember.js,Ember.js,我需要写一封信。下面的代码我已经写了一半了,但是我错过了路由器中的翻译。当前路径如何反映url ApplicationController中的当前代码: setCanonicalURL: function() { 'use strict'; $('head link[rel="canonical"]').attr("href", "http://website.com/" + this.get('currentRouteName')); }.observes('curr
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');
尝试:
而不是:
this.get('currentRouteName');
最终,优雅而简单:
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')
});
这里最重要的是路由器中路径的重命名。currentPath和currentRoute都返回search.index
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')
});