Feature Request: Add onPop support to AutoRouteGuard for post-navigation cleanup #2183
Ahmed-Larbi
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi AutoRoute team,
I’d like to suggest adding an onPop lifecycle callback to the AutoRouteGuard. Currently, the onNavigation method is only triggered when navigating into a route, but there’s no built-in way to detect when the user pops away from a guarded route.
In my use case, I’m initializing scoped dependencies when a user enters a specific route (e.g., ProgramDesignGalleryRoute) and want to clean up that scope when the route is removed from the stack. Right now, the only workaround is to attach a listener manually to the router inside the guard, which is not ideal or scalable.
Why onPop would help:
• It allows for proper resource cleanup tied to the route lifecycle.
• Keeps the guard self-contained instead of relying on global route listeners or external observers.
• Improves separation of concerns, since guards can both initialize and tear down dependencies safely.
• Makes it easier to implement route-based scoped logic (e.g., viewmodel disposal, DI teardown) in a more declarative way.
A possible API could be:
Thanks for your awesome work on AutoRoute — this feature would make it even more powerful for lifecycle-aware routing!
Best,
Ahmed
Beta Was this translation helpful? Give feedback.
All reactions