Flutter go_router: How to apply a common redirect to a specific group of routes?
I am using the go_router package in Flutter and need to apply a shared redirect logic (e.g., an admin check) to a specific subset of routes. I'm considering several approaches. Approach 1 I can use the global redirect on the GoRouter instance: final GoRouter _router = GoRouter( redirect: (context, state) { //Actual routing... return null; }, // ... ); However, I don't like this approach, because the global redirect shouldn't care about this redirect. Approach 2 I could create a commonRedirect function and pass it manually to the redirect parameter of every single GoRoute that needs it: String?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.