Skip to content
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

[go_router_10.0] fix router neglect and state restoration issue #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/go_router/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,22 @@ class RouteBuilder {
// https://github.com/flutter/flutter/issues/126365
final _PagePopContext pagePopContext =
_PagePopContext._(onPopPageWithRouteMatch);
List<Page<Object?>>? pages;
if (routerNeglect) {
Router.neglect(context, () {
pages = _buildPages(context, matchList, pagePopContext, routerNeglect,
navigatorKey, registry);
});
} else {
pages = _buildPages(context, matchList, pagePopContext, routerNeglect,
navigatorKey, registry);
}
assert(pages != null);
return builderWithNav(
context,
_buildNavigator(
pagePopContext.onPopPage,
_buildPages(context, matchList, pagePopContext, routerNeglect,
navigatorKey, registry),
pages!,
navigatorKey,
observers: observers,
restorationScopeId: restorationScopeId,
Expand Down
11 changes: 8 additions & 3 deletions packages/go_router/lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,21 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
if (configuration.isEmpty) {
return null;
}
final String location;
if (GoRouter.optionURLReflectsImperativeAPIs &&
configuration.matches.last is ImperativeRouteMatch) {
configuration =
(configuration.matches.last as ImperativeRouteMatch).matches;
location = (configuration.matches.last as ImperativeRouteMatch)
.matches
.uri
.toString();
} else {
location = configuration.uri.toString();
}
return RouteInformation(
// TODO(chunhtai): remove this ignore and migrate the code
// https://github.com/flutter/flutter/issues/124045.
// ignore: deprecated_member_use
location: configuration.uri.toString(),
location: location,
state: _routeMatchListCodec.encode(configuration),
);
}
Expand Down