Detect route transitions in EmberJS 1.0.0-pre.4

我只是一个虾纸丫 提交于 2019-12-02 01:12:31

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!