繁体   English   中英

Ember.js RC1获取路线名称

[英]Ember.js RC1 get name of route

我有一个ember应用程序,可以在其中进行一些条件重定向,但是希望在用户跳过某些箍之后将请求传递到其原始位置。

我有这样的东西(咖啡)

Ember.Route.reopen: ->
    redirect: ->
        if @controllerFor('specialOffers').get('should_offer')
            #This next line is what I need help with
            @controllerFor('specialOffers').set('pass_through', HOW_DO_I_GET_STRING_NAME_OF_CURRENT_ROUTE)
            # After this property is set and the user interacts
            # with the special offers, they will be redirected back
            # to wherever they intended to go
            @transitionTo('specialOffers')

您需要来自applicationController currentPath

App.ApplicationController = Ember.Controller.extend({
  printCurrentPath: function() {
    var currentPath = this.get('currentPath')
    console.log("The currentPath is " + currentPath);
  }.observes('currentPath')
}); 

然后,在您的任何控制器中,您都可以使用needs API从applicationController访问currentPath在此处阅读有关内容),如下所示:

App.SomeOtherController = Ember.Controller.extend({
  needs: ['application'],

  printCurrentPath: function() {
    var applicationController = this.get('controllers.application');
    var currentPath = applicationController.get('currentPath');
    console.log('Look ma, I have access to the currentPath: ' + currentPath);
  }.observes('controllers.application.currentPath')
});

这似乎可行...但是我不知道这是否是获得此价值的合法方法。

Ember.Route.reopen({
  redirect: function() {
    console.log(this.routeName);
  }
})

JSFiddle示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM