diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index 075e950d611..1ca2c72551c 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.0.1 + +- Fixes incorrect URL when pops multiple times + ## 6.0.0 - **BREAKING CHANGE** diff --git a/packages/go_router/lib/src/path_utils.dart b/packages/go_router/lib/src/path_utils.dart index d7a20ff22d5..9f519573025 100644 --- a/packages/go_router/lib/src/path_utils.dart +++ b/packages/go_router/lib/src/path_utils.dart @@ -78,7 +78,7 @@ String removePatternFromPath(String pattern, String path) { } if (!pattern.endsWith('/')) { - buffer.write(r'(?=/|$)'); + buffer.write(r'(\/)?(?=/|$)'); } buffer.write(r'$'); final RegExp regexp = RegExp(buffer.toString(), caseSensitive: false); diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index edcfd0a077a..46982a9f932 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.0.0 +version: 6.0.1 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 560a429d508..a7c981e04f0 100644 --- a/packages/go_router/test/go_router_test.dart +++ b/packages/go_router/test/go_router_test.dart @@ -953,6 +953,41 @@ void main() { ]); }); + testWidgets('on pop twice', (WidgetTester tester) async { + final List routes = [ + GoRoute( + path: '/', + builder: (_, __) => const DummyScreen(), + routes: [ + GoRoute( + path: 'settings', + builder: (_, __) => const DummyScreen(), + routes: [ + GoRoute( + path: 'profile', + builder: (_, __) => const DummyScreen(), + ), + ]), + ]), + ]; + + final GoRouter router = await createRouter(routes, tester, + initialLocation: '/settings/profile'); + + log.clear(); + router.pop(); + router.pop(); + await tester.pumpAndSettle(); + expect(log, [ + isMethodCall('selectMultiEntryHistory', arguments: null), + isMethodCall('routeInformationUpdated', arguments: { + 'location': '/', + 'state': null, + 'replace': false + }), + ]); + }); + testWidgets('on pop with path parameters', (WidgetTester tester) async { final List routes = [ GoRoute(