2

条件付きリダイレクトを行う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')
4

2 に答える 2

4

あなたが欲しいcurrentPathからapplicationController

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

次に、任意のコントローラーで、次のようにAPIを使用してcurrentPathから にアクセスできます (詳細については、こちらを参照してください)。applicationControllerneeds

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')
});
于 2013-03-02T23:01:31.783 に答える
2

これはうまくいくようです...しかし、それがこの値を取得するための正当な方法であるかどうかはわかりません。

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

JSFiddleの例

于 2013-03-02T22:41:14.343 に答える