Ember.js在每次转换时调用路由钩 [英] Ember.js route hook to be called on every transition
问题描述
即使新路由与旧路由相同(例如,单击同一路由的顶级导航链接),Ember.js中的每个转换都会调用路由钩子。 p>
我尝试过 activate
,但是只会被调用一次,当我使用顶级导航到我已经在同一条路线。
示例jsFiddle :当我第一次单击测试时,调用激活
钩子,但是当我第二次点击它时,它不会。
您可以在路由器中设置一个didTransition,完全是Ember为Google Analytics(分析)做的。
App.Router.reopen({
doSomething:function(){
// do something here
return;
} ('didTransition')
});
请参见示例: http://emberjs.com/guides/cookbook/helpers_and_components/adding_google_analytics_tracking/
Is there a route hook in Ember.js that is called on every transition, even if the new route is the same as the old route (for example, clicking a top-level navigation link to the same route).
I tried activate
, but it's only being called once, and is not being called again when I use the top-level navigation to go to the same route I'm already in.
Example jsFiddle: When I click "Test" the first time, the activate
hook is called, but when I click it a second time, it does not.
You can setup a didTransition in the router, exactly how Ember does it for Google Analytics.
App.Router.reopen({
doSomething: function() {
// do something here
return;
}.on('didTransition')
});
See example here: http://emberjs.com/guides/cookbook/helpers_and_components/adding_google_analytics_tracking/
这篇关于Ember.js在每次转换时调用路由钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!