Ember.js RC1获取路线名称

时间:2013-03-02 22:19:28

标签: javascript coffeescript ember.js ember-router

我有一个ember应用程序,我在那里进行一些条件重定向,但是希望能够在用户跳过一些环节之后将请求传递到它的原始位置。

我有类似的东西(coffeescript)

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')

2 个答案:

答案 0 :(得分:4)

您希望来自currentPath的{​​{1}}:

applicationController

然后,您可以在任何控制器中使用App.ApplicationController = Ember.Controller.extend({ printCurrentPath: function() { var currentPath = this.get('currentPath') console.log("The currentPath is " + currentPath); }.observes('currentPath') }); API(阅读here)从currentPath访问applicationController,如下所示:< / p>

needs

答案 1 :(得分:2)

这似乎有效......但我不知道这是否是获得此价值的合法途径。

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

JSFiddle Example