diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 28ee780a10e..3baca0cbbb2 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 11.1.3 + +- Fixes missing state.extra in onException(). + ## 11.1.2 - Fixes a bug where the known routes and initial route were logged even when `debugLogDiagnostics` was set to `false`. diff --git a/packages/go_router/lib/src/configuration.dart b/packages/go_router/lib/src/configuration.dart index 4c9c018ed80..24c16e342b8 100644 --- a/packages/go_router/lib/src/configuration.dart +++ b/packages/go_router/lib/src/configuration.dart @@ -188,9 +188,14 @@ class RouteConfiguration { } /// The match used when there is an error during parsing. - static RouteMatchList _errorRouteMatchList(Uri uri, GoException exception) { + static RouteMatchList _errorRouteMatchList( + Uri uri, + GoException exception, { + Object? extra, + }) { return RouteMatchList( matches: const [], + extra: extra, error: exception, uri: uri, pathParameters: const {}, @@ -277,7 +282,10 @@ class RouteConfiguration { if (matches == null) { return _errorRouteMatchList( - uri, GoException('no routes for location: $uri')); + uri, + GoException('no routes for location: $uri'), + extra: extra, + ); } return RouteMatchList( matches: matches, diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index c4d4154fdd9..9fb123c99ff 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: 11.1.2 +version: 11.1.3 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/exception_handling_test.dart b/packages/go_router/test/exception_handling_test.dart index e3e6906abdd..d8ad3c3f565 100644 --- a/packages/go_router/test/exception_handling_test.dart +++ b/packages/go_router/test/exception_handling_test.dart @@ -77,6 +77,21 @@ void main() { expect(find.text('redirected /some-other-location'), findsOneWidget); }); + testWidgets('can redirect with extra', (WidgetTester tester) async { + final GoRouter router = await createRouter([ + GoRoute( + path: '/error', + builder: (_, GoRouterState state) => Text('extra: ${state.extra}')), + ], tester, + onException: (_, GoRouterState state, GoRouter router) => + router.go('/error', extra: state.extra)); + expect(find.text('extra: null'), findsOneWidget); + + router.go('/some-other-location', extra: 'X'); + await tester.pumpAndSettle(); + expect(find.text('extra: X'), findsOneWidget); + }); + testWidgets('stays on the same page if noop.', (WidgetTester tester) async { final GoRouter router = await createRouter( [