Skip to content

Commit

Permalink
[go_router]Fixes the problem what pathParameters is null in redirect …
Browse files Browse the repository at this point in the history
…when the Router is recreated. (flutter#5258)

fixes flutter/flutter#135761
  • Loading branch information
yiiim authored and HugoOlthof committed Dec 13, 2023
1 parent 09acce9 commit a3405e2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
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

0 comments on commit a3405e2

Please sign in to comment.