diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index f1b1b261713..78fee03acac 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -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. diff --git a/packages/go_router/lib/src/configuration.dart b/packages/go_router/lib/src/configuration.dart index 8e6393503a5..16f38f3b271 100644 --- a/packages/go_router/lib/src/configuration.dart +++ b/packages/go_router/lib/src/configuration.dart @@ -495,17 +495,19 @@ class RouteConfiguration { final RouteBase route = match.route; FutureOr 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, ), ); diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index dbf0f854a33..dfce6f6feed 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -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 diff --git a/packages/go_router/test/go_router_test.dart b/packages/go_router/test/go_router_test.dart index d2b3e91a002..213b27ab60e 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -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: [ + GoRoute( + path: '/foo', + builder: dummy, + routes: [ + 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> {