ember路线名称照顾路径

时间:2015-01-09 21:28:38

标签: ember.js

我需要写一个<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');

2 个答案:

答案 0 :(得分: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')
});

答案 1 :(得分:-1)

尝试:

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

而不是:

this.get('currentRouteName');
相关问题