Skip to content

Commit e4c5159

Browse files
authored
[go_router]Fixes the problem what pathParameters is null in redirect when the Router is recreated. (#5258)
fixes flutter/flutter#135761
1 parent 5842d3d commit e4c5159

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 12.0.2
2+
3+
- Fixes the problem that pathParameters is null in redirect when the Router is recreated.
4+
15
## 12.0.1
26

37
- Fixes deep-link with no path on cold start.

packages/go_router/lib/src/configuration.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,17 +495,19 @@ class RouteConfiguration {
495495
final RouteBase route = match.route;
496496
FutureOr<String?> routeRedirectResult;
497497
if (route is GoRoute && route.redirect != null) {
498+
final RouteMatchList effectiveMatchList =
499+
match is ImperativeRouteMatch ? match.matches : matchList;
498500
routeRedirectResult = route.redirect!(
499501
context,
500502
GoRouterState(
501503
this,
502-
uri: matchList.uri,
504+
uri: effectiveMatchList.uri,
503505
matchedLocation: match.matchedLocation,
504506
name: route.name,
505507
path: route.path,
506-
fullPath: matchList.fullPath,
507-
extra: matchList.extra,
508-
pathParameters: matchList.pathParameters,
508+
fullPath: effectiveMatchList.fullPath,
509+
extra: effectiveMatchList.extra,
510+
pathParameters: effectiveMatchList.pathParameters,
509511
pageKey: match.pageKey,
510512
),
511513
);

packages/go_router/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 12.0.1
4+
version: 12.0.2
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

packages/go_router/test/go_router_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,6 +5048,44 @@ void main() {
50485048
expectedInitialRoute);
50495049
});
50505050
});
5051+
5052+
testWidgets(
5053+
'test the pathParameters in redirect when the Router is recreated',
5054+
(WidgetTester tester) async {
5055+
final GoRouter router = GoRouter(
5056+
initialLocation: '/foo',
5057+
routes: <RouteBase>[
5058+
GoRoute(
5059+
path: '/foo',
5060+
builder: dummy,
5061+
routes: <GoRoute>[
5062+
GoRoute(
5063+
path: ':id',
5064+
redirect: (_, GoRouterState state) {
5065+
expect(state.pathParameters['id'], isNotNull);
5066+
return null;
5067+
},
5068+
builder: dummy,
5069+
),
5070+
],
5071+
),
5072+
],
5073+
);
5074+
await tester.pumpWidget(
5075+
MaterialApp.router(
5076+
key: UniqueKey(),
5077+
routerConfig: router,
5078+
),
5079+
);
5080+
router.push('/foo/123');
5081+
await tester.pump(); // wait reportRouteInformation
5082+
await tester.pumpWidget(
5083+
MaterialApp.router(
5084+
key: UniqueKey(),
5085+
routerConfig: router,
5086+
),
5087+
);
5088+
});
50515089
}
50525090

50535091
class TestInheritedNotifier extends InheritedNotifier<ValueNotifier<String>> {

0 commit comments

Comments
 (0)