You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this listener is never torn down, and will fire for all transitions in the app, regardless if they are from or to the current route.
exportdefaultclassFormRouteextendsRoute{
@servicerouter;constructor(){super(...arguments);this.router.on('routeWillChange',(transition)=>{if(!transition.to.find(route=>route.name===this.routeName)&&!confirm('Are you sure you want to abandon progress?')){transition.abort();}});}};
I'd like to open a PR to include information about using router.off here. Would that be helpful?
The text was updated successfully, but these errors were encountered:
deanmarano
changed the title
Teardown of this.router.on usage in "Preventing and Retrying Transitions"
Include teardown of this.router.on in "Preventing and Retrying Transitions"
Nov 20, 2024
In the guides, it is suggested to use
this.router.on
as a way to prevent a route transition:https://guides.emberjs.com/release/routing/preventing-and-retrying-transitions/#toc_preventing-transitions-via-routewillchange
However, this listener is never torn down, and will fire for all transitions in the app, regardless if they are from or to the current route.
I'd like to open a PR to include information about using
router.off
here. Would that be helpful?The text was updated successfully, but these errors were encountered: