Milad-Akarie/parallel-navigation-demo-auto-route

Adding guards on Profile routes

Closed this issue · 1 comments

Hello,

I have a project where the navigation is basically based on this repository.
I am trying to add an AuthGuard to routes similar to Profile routes, checking authentication, redirecting to SignIn page otherwise.
I saw code examples here Milad-Akarie/auto_route_library#53

However the canNavigate() navigator argument is an instance of the router of the page we try to visit. Can we access an other router inside canNavigate() if we want to access a page in an other tab?

Also if I hack my code to execute canNavigate() with the proper navigator, trying to redirect on an other page from the same router like so return navigator.push(AccountRoutes.signInPage);, then I got this error:
Unhandled Exception: type 'MaterialPageRoute<dynamic>' is not a subtype of type 'Route<bool>' in type cast.

Am I doing something wrong or guards are not suited for this use case?
Thank you for your help.

I ended up moving my root routes to one of the Stack, so I can navigate between root routes and IndexedStack routes.
Also I hide the bottom navbar with Opacity on root routes. It's a bit hacky but well I haven't found better.

And I use a HomePage that handles redirection according to state, instead of Auth guards.