Detect route transitions in EmberJS 1.0.0-pre.4

后端 未结 1 1747
星月不相逢
星月不相逢 2021-01-21 13:24

I am trying to detect when a route transition occurs. I\'ve located this code snippet inside the latest version of Ember (v1.0.0-pre.4) that handles the transitions

相关标签:
1条回答
  • 2021-01-21 14:26

    UPDATED ANSWER

    You can now simply bind an observer on the router's didTransition event:

    App.Router.reopen({
      doSomethingOnUrlChange: function() {
        console.log(this.get('url'));
      }.on('didTransition')  
    });
    

    see working example: http://jsfiddle.net/Sly7/3THD7/

    DEPRECATED ANSWER BELOW

    In the snippet here, there is set(appController, 'currentPath', path); I think you can put an observer on this property.

    I don't know exactly where you want to be notified, but it's possible to do it in the ApplicationController itself.

    App.ApplicationController = Ember.Controller.extend({
    
      currentPathDidChange: function(){
        // the currentPath has changed;
      }.observes('currentPath');
    });
    

    See this working fiddle for example: http://jsfiddle.net/qKrwU/

    0 讨论(0)
提交回复
热议问题