-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router] Support for top level onEnter callback.
#8339
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
Changes from 1 commit
6be9a5d
171b639
f52a269
3bbd241
6a60006
d1e1fc2
516db13
e1f10b1
7a847b8
b08d804
1e25466
aec8e47
2bdc147
1bd3c18
61729b2
8334a64
f28337e
4092405
c1c09d0
d9e6ea6
07c15f0
3fbe011
67df52a
eef39b1
359eb0e
cc57519
d4f2416
56f2dbe
c458982
921dcb3
757f5a1
b5e1e9e
86c506b
3c4a85f
9d52c0d
97c5ed8
0323a45
4a9e6ff
3b2df49
1dd95d8
ade3f54
ed43b0b
d0d5e6d
a484965
10404f8
2b3d0be
b554e6c
99ab3c3
265f26f
01f7ea6
22a29bd
887c528
37712e5
ee55004
9e37af9
faa9d81
20c4148
2b4c348
d1bc684
54afc72
33996c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Provides access to GoRouter within OnEnter callback to support navigation during early routing stages when InheritedGoRouter is not yet available in the widget tree.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,10 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> { | |
| GoRouteInformationParser({ | ||
| required this.configuration, | ||
| required String? initialLocation, | ||
| required GoRouter fallbackRouter, | ||
| required this.onParserException, | ||
| }) : _routeMatchListCodec = RouteMatchListCodec(configuration), | ||
| }) : _fallbackRouter = fallbackRouter, | ||
| _routeMatchListCodec = RouteMatchListCodec(configuration), | ||
| _initialLocation = initialLocation; | ||
|
|
||
| /// The route configuration used for parsing [RouteInformation]s. | ||
|
|
@@ -52,6 +54,25 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> { | |
| /// Store the last successful match list so we can truly "stay" on the same route. | ||
| RouteMatchList? _lastMatchList; | ||
|
|
||
| /// The fallback [GoRouter] instance used during route information parsing. | ||
|
||
| /// | ||
| /// During initial app launch or deep linking, route parsing may occur before the | ||
| /// [InheritedGoRouter] is built in the widget tree. This makes [GoRouter.of] or | ||
| /// [GoRouter.maybeOf] unavailable through [BuildContext]. | ||
| /// | ||
| /// When route parsing happens in these early stages, [_fallbackRouter] ensures that | ||
| /// navigation APIs remain accessible to features like [OnEnter], which may need to | ||
| /// perform navigation before the widget tree is fully built. | ||
| /// | ||
| /// This is used internally by [GoRouter] to pass its own instance as | ||
| /// the fallback. You typically don't need to provide this when constructing a | ||
| /// [GoRouteInformationParser] directly. | ||
| /// | ||
| /// See also: | ||
| /// * [parseRouteInformationWithDependencies], which uses this fallback router | ||
| /// when [BuildContext]-based router access is unavailable. | ||
| final GoRouter _fallbackRouter; | ||
|
|
||
| /// The future of current route parsing. | ||
| /// | ||
| /// This is used for testing asynchronous redirection. | ||
|
|
@@ -116,6 +137,7 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> { | |
| context, | ||
| currentState, | ||
| nextState, | ||
| GoRouter.maybeOf(context) ?? _fallbackRouter, | ||
| ); | ||
|
|
||
| // If navigation was intercepted (canEnter == false): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.