Couple of reasons that might not be working:
-
putting actions in a hash is an old syntax which we no longer use in Discourse. Theoretically it should work, but the interop with the new syntax might not be perfect. The modern way would be
api.modifyClass("route:application", (Superclass) => class extends Superclass { @action willTransition(){ console.log("do something"); super.willTransition(...arguments); } });standard modifyClass disclaimer applies: this is risky and could break at any time
-
I don’t think
willTransitionis guaranteed to fire on the application route in all situations. (e.g. if a child route has a willTransition action, it won’t necessarily bubble up)
I’d recommend using the events on the Ember router service instead: RouterService | 5.12.0 | Ember API Documentation
e.g. something like
const router = api.container.lookup("service:router");
router.on("routeWillChange", () => {
console.log("route will change fired");
});