Search code examples
ember.jsoperator-precedence

when will the activate hook run in route level for ember app


form the api document,"This hook is executed when the router enters the route. It is not executed when the model for the route changes." but I can't really understand it due to some confusion.

for example,here, I have route name "xxx.yyy" in route xxx, I set hook function: 'beforeModel','model','afterModel','activate','setupController'.debugger in each; the same to the route yyy.

then, when I start the debug, I found the call order is that:

'xxx:beforeModel'->'xxx:model'->'xxx:afterModel'->'yyy:beforeModel'->'yyy:model'->'yyy:afterModel'->'xxx:activate'->'xxx:setupController'->'yyy:activate'->'yyy:setupController'.

why the yyy:beforeModel is called ahead of the xxx:activate ???

as I know, if xxx:afterModel return a promise, it will wait until it fullfilled(or switch into the loading route), after the promise is done, to me ,it means we almost enter into the route xxx ,so the xxx:activate should be called next. but instead, the next is yyy:beforeModel actually

who can tell me the reason??


Solution

  • When transitioning to a route, all models are resolved before activating/setting up the controllers.