diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 86002df3f2f..9ceedfd82aa 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.2.5 + +- Fixes a bug where calling extra parameter is always null in route level redirect callback + ## 4.2.4 - Rewrites Readme and examples. diff --git a/packages/go_router/lib/src/redirection.dart b/packages/go_router/lib/src/redirection.dart index 29b541d786c..400ef8b7d5e 100644 --- a/packages/go_router/lib/src/redirection.dart +++ b/packages/go_router/lib/src/redirection.dart @@ -78,6 +78,7 @@ RouteMatchList redirect(RouteMatchList prevMatchList, name: top.route.name, path: top.route.path, fullpath: top.fullpath, + extra: top.extra, params: top.decodedParams, queryParams: top.queryParams, ), diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 722962eff14..9ba26d8b769 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: 4.2.4 +version: 4.2.5 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 15b23c27da6..5758a580aa4 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -1170,6 +1170,54 @@ void main() { (router.screenFor(matches.first) as TestErrorScreen).ex, isNotNull); log.info((router.screenFor(matches.first) as TestErrorScreen).ex); }); + + testWidgets('extra not null in redirect', (WidgetTester tester) async { + bool isCallTopRedirect = false; + bool isCallRouteRedirect = false; + + final List routes = [ + GoRoute( + name: 'home', + path: '/', + builder: (BuildContext context, GoRouterState state) => + const HomeScreen(), + routes: [ + GoRoute( + name: 'login', + path: 'login', + builder: (BuildContext context, GoRouterState state) { + return const LoginScreen(); + }, + redirect: (GoRouterState state) { + isCallRouteRedirect = true; + expect(state.extra, isNotNull); + return null; + }, + routes: [], + ), + ], + ), + ]; + + final GoRouter router = await createRouter( + routes, + tester, + redirect: (GoRouterState state) { + if (state.location == '/login') { + isCallTopRedirect = true; + expect(state.extra, isNotNull); + } + + return null; + }, + ); + + router.go('/login', extra: 1); + await tester.pump(); + + expect(isCallTopRedirect, true); + expect(isCallRouteRedirect, true); + }); }); group('initial location', () {