Route activate() method not called when using router.transitionTo

In my route.js file, I use the activate() method to initiate something.

In the template associated with this route, I have an input that makes it possible to navigate to the same route but with a different object ID.

I use router.transitionTo like so

get(this, 'router').transitionTo('route', objectId);

But this transition does not trigger the activate() method.

Now the doc says

This hook is executed when the router enters the route. It is not executed when the model for the route changes.

I guess this is why it’s not working (I am staying on the same route, simply using a new model).

Is there a way around this? How can I make sure that the activate() method gets call in my use case?

Hi @Frank, I think you’re correct. When the model changes it’s not considered a full route exit/enter. The same applies to the resetController hook, for example, where you have a flag called isExiting which signals when the route is being exited vs the model is changing.

As far as what to do about it… you have some options. I’d think you’d want to abstract what you currently have in activate into a different method, and then call that method from a different hook/event. You could maybe use didTransition, or even one of the beforeModel/model/afterModel hooks. You could also probably use the router service routeDidChange event.

Much thanks for the help! I’ll see if I can figure something out!