Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.57k stars 394 forks source link

Make AutoRouteGuards work when a route is popped to #2042

Open jtmuller5 opened 3 weeks ago

jtmuller5 commented 3 weeks ago

AutoRouteGuards only work for "forward" navigation. It would be awesome if we could configure each AutoRouteGuard to also work for "backward" navigation (ex. when the route on top of the protected route is popped off or when a user presses the browser back button in Flutter web).

The main use case for this is to show a confirmation popup when a user tries to exit a screen. This is useful when editing forms or other screens that can lose progress.

I created a repo that illustrates the issue:

Sample repo (check auto_route folder): https://github.com/CodeOTR/flutter_web_navigation

In go_router, you can accomplish this by adding an onExit function to any route.

https://github.com/user-attachments/assets/b6960657-0b98-42a4-8307-1ca631e4175b

proninyaroslav commented 3 weeks ago

Agree. I was looking for this in the documentation today, thinking that it was implemented in AutoRouteGuard. In my case, the authorization should expire after moving back in the stack. In the current implementation of AutoRouteGuard, this is not possible.
This can probably be done with AutoRouterObserver, but it would be useful to have it in AutoRouteGuard since it doesn't require a global observer to be installed.