[go_router_builder] GoRouteData `redirect` function has no context nor state parameters

This issue has been created since 2022-11-23.


The pain point described here is that GoRouteData's redirect differs, or rather lacks, from GoRouter's. See GoRouter's redirect vs GoRouteData's redirect.

Without GoRouteData matching GoRouter 's 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 GoRouter with Riverpod (or Provider for what matters).

Use case

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
Details of the use case

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 home since 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.


Let GoRouteData have a FutureOr<String?> Function(BuildContext, GoRouterState) redirect parameter instead of the current simple FutureOr<String?> redirect().

This allows the developer to inject state through BuildContext and use GoRouterState when needed.

exaby73 wrote this answer on 2022-11-24

Hello @lucavenir. Thank you for the proposal. Looks like a valid one to me. Labeling for visibility by the team

lucavenir wrote this answer on 2022-11-24

Thank you @exaby73. I want to underline how this behavior might be desirable with builder in GoRouteData. Note how that method lacks a GoRouterState parameter (which is normally found in GoRouter).

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.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-10
Star Count 147243
Watcher Count 3561
Fork Count 23950
Issue Count 11325


Issue Title Created Date Comment Count Updated Date
Calculation of maxScrollPosition 1 2022-04-28 2022-10-15
tlmgr does NOT update any package during build 5 2020-01-30 2022-12-01
"shadow" appears on disparity result 1 2021-03-08 2022-12-09
support for goland 2021.3.2 1 2022-01-11 2022-10-22
Shortening the Legendre Transform over m 10 2022-08-26 2022-09-29
Broadcast operations with LowerTriangularMatrix 8 2022-08-31 2022-09-29
Fix mypy issue: "OceanNoEvmWalletMixIn" has no attribute "_USD" 1 2022-01-22 2022-10-13
Maintenance: e2e tests failing due to version mismatch 2 2022-10-11 2022-12-02
Runtime in uplink.dm,157: Cannot modify null.authenticated. 2 2022-05-05 2022-10-01
CRAN and reverse dependency check (**classInt**) failure 1 2022-06-07 2022-10-11
Some issues related to mfcc feature extraction 6 2021-10-20 2022-09-16
ERROR: The "data" argument must be of type string or ... 1 2022-06-29 2022-11-16
Alternatives for module loading of AudioWorklet 5 2020-12-15 2022-11-05
无法通过 CDN(Cloudflare)连接到服务器 3 2022-07-30 2022-11-21
ReferenceError: unknown node of type "ChainExpression" with constructor "Object" 2 2021-07-26 2022-05-15
怎样取消-w 60的默认值 3 2021-08-13 2022-01-21
A doubt about persistence 1 2022-06-30 2022-12-02
there is no generic ptr type 0 2021-06-08 2022-12-02
Release test v6.85.0 1 2022-12-07 2022-12-03
[MU4 Issue] Slurs imported from MS3 shift to wrong position in MS4 3 2022-04-30 2022-11-26
How can I use trained espnet/egs/ljspeech/tts1 model to generate audio 1 2021-11-28 2022-10-10
Public Rule api returns 401 on the server when long time no request 10 2022-05-25 2022-10-14
No spacing between ok/cancel buttons in Custom text/numeric dialogs 0 2022-03-19 2022-10-10
Suggestion: Add warning if removing in-use Thing or Adapter 2 2021-04-09 2022-10-14
eMMC: Decoding of SEND_EXT_CSD command output 0 2021-11-17 2022-10-15
Monkeys can transfer heart disease by biting others 1 2022-02-24 2022-09-22
Support nrlint --version 0 2021-11-01 2022-11-01
Flag to disable headless vectors 2 2022-05-18 2022-12-03
section `.text1' will not fit in region `iram1_0_seg' 7 2022-02-16 2022-08-03
[Task]: Error message without an error 5 2022-03-11 2022-09-29
Query parameters with custom annotations are always required 2 2022-01-17 2022-10-14
Print / export blackList(s) 4 2021-12-09 2022-09-13
Library applying track title filter when selecting a track 1 2022-06-13 2022-12-01
Support for BLS12 based signature verification 0 2021-09-27 2022-07-23
More visible and distinguishable progress indicator for loading the page 1 2022-07-07 2022-10-15
learn-anything.xyz 0 2021-12-10 2022-01-15
Quieting printGeneratedCodeForStack() from outputting entire (large) files to console? 3 2022-09-27 2022-11-11
Fixing a spelling issue in bash.sh 1 2021-07-11 2022-12-08
CNCF Artifact Hub repo 20 2020-12-07 2022-12-02
Pass linting checks 2 2021-01-29 2022-01-01
Release kubesphere-extension and update the version 1 2020-11-11 2022-12-04
KSI doc needs improvement 1 2015-10-26 2022-11-03
[Feature] Modify eventmesh-catalog internal module 0 2022-10-01 2022-10-10
Bump documentation to release version 4.2.6 1 2022-03-25 2022-11-05
"28*28 masks", what is that? 0 2021-08-18 2022-10-05
Broke links 2 2021-09-10 2022-01-23
如何动态设置静默模式,目前只能在配置中设置isSilentMode:true 1 2021-10-23 2022-07-26
USB_serial_for_android 1 2022-02-10 2022-11-29
Error in the docs, in section Configure Service Accounts for Pods 1 2022-12-09 2022-12-03
Change value escape of 'out' parameters to ReturnOnly 5 2022-09-20 2022-09-22