Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AutoRouteGuards work when a route is popped to #2042

Open
jtmuller5 opened this issue Aug 20, 2024 · 1 comment
Open

Make AutoRouteGuards work when a route is popped to #2042

jtmuller5 opened this issue Aug 20, 2024 · 1 comment

Comments

@jtmuller5
Copy link

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:

  • Press "Screen one"
  • [Guard dialog appears]
  • Press "Confirm"
  • [Navigate to Screen Two]
  • Press the back arrow
  • [Guard dialog does not appear]

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.

auto_route_guard.mov
@proninyaroslav
Copy link

proninyaroslav commented Aug 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants