redirect APIs, I am unable to inject state or to read the request sublocation and therefore I have to give up on typed routing.
The root of the problem arises from integrating
Provider for what matters).
I am venturing through
go_router_builder and I am trying to make it work with my state management solution.
So far, so good.
Then, I tried implementing a sub-route with a route-level redirection. Say you have the following (simplified) routes:
+ splash + login + home ++ admin ++ dashboard ++ guest-view
The user opens the app and sees a splash page. He is not logged in, and therefore should be redirected towards
login. Then, the users chooses to login as a guest. Just like that, he's redirected to
home. The user tries to navigate to
admin, but he's redirected back to
homesince he has not enough permissions. Some sort of feedback is showed to the user.
As detailed above, the crucial part here is being able to write route-level logic that redirects an unauthenticated but not unauthorized user, e.g. a guest user trying to access an admin page. Without codegen, I usually do this via route-level redirects. I read some state via
ref.read (Riverpod) and then make decisions based on those results.
Unluckily, this is not currently possible via
GoRouteData and the codegen APIs. Or at least it looks like it.
GoRouteData have a
FutureOr<String?> Function(BuildContext, GoRouterState) redirect parameter instead of the current simple
This allows the developer to inject state through
BuildContext and use
GoRouterState when needed.
Thank you @exaby73. I want to underline how this behavior might be desirable with
GoRouteData. Note how that method lacks a
GoRouterState parameter (which is normally found in
That might be de desirable, I guess that works, as we're defining
GoRouteData to directly accept typed parameters in its subclass, and let
go_router_builder generate those APIs for us.
But in case of
redirect I don't think it's possible to write logic without
BuildContext (i.e. we need global state and we need
context to do so) or on
GoRouterState (i.e. while I do have the parameters, I lack the information about the requested sublocation).
If there's a way to make that work, please let me know, i.e. this becomes a documentation request rather than a feature request.
|Issue Title||Created Date||Updated Date|