diff --git a/AUTHORS b/AUTHORS index 23670fbe0cd4..8675987f81b3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -71,3 +71,4 @@ TheOneWithTheBraid Rulong Chen(陈汝龙) Hwanseok Kang Twin Sun, LLC +Amir Panahandeh diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 4a72e8a35008..0d9ac7513739 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.5.3 + +- Fixes redirect being called with an empty location for unknown routes. + ## 6.5.2 - NoTransitionPage now has an instant reverse transition diff --git a/packages/go_router/lib/src/parser.dart b/packages/go_router/lib/src/parser.dart index 37c3e98bd023..c047474b321c 100644 --- a/packages/go_router/lib/src/parser.dart +++ b/packages/go_router/lib/src/parser.dart @@ -11,7 +11,9 @@ import 'configuration.dart'; import 'delegate.dart'; import 'information_provider.dart'; import 'logging.dart'; +import 'match.dart'; import 'matching.dart'; +import 'path_utils.dart'; import 'redirection.dart'; /// Converts between incoming URLs and a [RouteMatchList] using [RouteMatcher]. @@ -63,7 +65,11 @@ class GoRouteInformationParser extends RouteInformationParser { // If there is a matching error for the initial location, we should // still try to process the top-level redirects. - initialMatches = RouteMatchList.empty; + initialMatches = RouteMatchList( + [], + Uri.parse(canonicalUri(routeInformation.location!)), + const {}, + ); } Future processRedirectorResult(RouteMatchList matches) { if (matches.isEmpty) { diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 873ed655dacb..b9e11e10cc9d 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: 6.5.2 +version: 6.5.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/parser_test.dart b/packages/go_router/test/parser_test.dart index cac9a552fb3c..e083ffdca02b 100644 --- a/packages/go_router/test/parser_test.dart +++ b/packages/go_router/test/parser_test.dart @@ -196,6 +196,38 @@ void main() { 'Exception: no routes for location: /def'); }); + testWidgets( + 'GoRouteInformationParser calls redirector with correct uri when unknown route', + (WidgetTester tester) async { + String? lastRedirectLocation; + final List routes = [ + GoRoute( + path: '/', + builder: (_, __) => const Placeholder(), + routes: [ + GoRoute( + path: 'abc', + builder: (_, __) => const Placeholder(), + ), + ], + ), + ]; + final GoRouteInformationParser parser = await createParser( + tester, + routes: routes, + redirectLimit: 100, + redirect: (_, GoRouterState state) { + lastRedirectLocation = state.location; + return null; + }, + ); + + final BuildContext context = tester.element(find.byType(Router)); + await parser.parseRouteInformationWithDependencies( + const RouteInformation(location: '/def'), context); + expect(lastRedirectLocation, '/def'); + }); + testWidgets('GoRouteInformationParser can work with route parameters', (WidgetTester tester) async { final List routes = [