Skip to content

[go_router]Fixes the problem what pathParameters is null in redirect when the Router is recreated. #5258

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

Merged
merged 4 commits into from
Nov 2, 2023
Merged
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
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 12.0.2

- Fixes the problem that pathParameters is null in redirect when the Router is recreated.

## 12.0.1

- Fixes deep-link with no path on cold start.
Expand Down
10 changes: 6 additions & 4 deletions packages/go_router/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,17 +495,19 @@ class RouteConfiguration {
final RouteBase route = match.route;
FutureOr<String?> routeRedirectResult;
if (route is GoRoute && route.redirect != null) {
final RouteMatchList effectiveMatchList =
match is ImperativeRouteMatch ? match.matches : matchList;
routeRedirectResult = route.redirect!(
context,
GoRouterState(
this,
uri: matchList.uri,
uri: effectiveMatchList.uri,
matchedLocation: match.matchedLocation,
name: route.name,
path: route.path,
fullPath: matchList.fullPath,
extra: matchList.extra,
pathParameters: matchList.pathParameters,
fullPath: effectiveMatchList.fullPath,
extra: effectiveMatchList.extra,
pathParameters: effectiveMatchList.pathParameters,
pageKey: match.pageKey,
),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 12.0.1
version: 12.0.2
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
38 changes: 38 additions & 0 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5048,6 +5048,44 @@ void main() {
expectedInitialRoute);
});
});

testWidgets(
'test the pathParameters in redirect when the Router is recreated',
(WidgetTester tester) async {
final GoRouter router = GoRouter(
initialLocation: '/foo',
routes: <RouteBase>[
GoRoute(
path: '/foo',
builder: dummy,
routes: <GoRoute>[
GoRoute(
path: ':id',
redirect: (_, GoRouterState state) {
expect(state.pathParameters['id'], isNotNull);
return null;
},
builder: dummy,
),
],
),
],
);
await tester.pumpWidget(
MaterialApp.router(
key: UniqueKey(),
routerConfig: router,
),
);
router.push('/foo/123');
await tester.pump(); // wait reportRouteInformation
await tester.pumpWidget(
MaterialApp.router(
key: UniqueKey(),
routerConfig: router,
),
);
});
}

class TestInheritedNotifier extends InheritedNotifier<ValueNotifier<String>> {
Expand Down