[go_router] Fixes an issue where the params are removed after popping (#3401)

[go_router] Fixes an issue where the params are removed after popping
diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md
index e8c655b..bd12b66 100644
--- a/packages/go_router/CHANGELOG.md
+++ b/packages/go_router/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 6.5.1
+
+- Fixes an issue where the params are removed after popping.
+
 ## 6.5.0
 
 - Supports returning values on pop.
@@ -20,7 +24,7 @@
 
 ## 6.2.0
 
-- Export supertypes in route_data.dart library
+- Exports supertypes in route_data.dart library.
 
 ## 6.1.0
 
diff --git a/packages/go_router/lib/src/builder.dart b/packages/go_router/lib/src/builder.dart
index ebb382d..72d0574 100644
--- a/packages/go_router/lib/src/builder.dart
+++ b/packages/go_router/lib/src/builder.dart
@@ -274,7 +274,7 @@
       name: name,
       path: path,
       fullpath: effectiveMatchList.fullpath,
-      params: effectiveMatchList.pathParameters,
+      params: Map<String, String>.from(effectiveMatchList.pathParameters),
       error: match.error,
       queryParams: effectiveMatchList.uri.queryParameters,
       queryParametersAll: effectiveMatchList.uri.queryParametersAll,
diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml
index 991a4f9..398ba21 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.0
+version: 6.5.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_state_test.dart b/packages/go_router/test/go_router_state_test.dart
index 65a0017..59cee73 100644
--- a/packages/go_router/test/go_router_state_test.dart
+++ b/packages/go_router/test/go_router_state_test.dart
@@ -67,6 +67,41 @@
       expect(find.text('1 /a', skipOffstage: false), findsOneWidget);
     });
 
+    testWidgets('path parameter persists after page is popped',
+        (WidgetTester tester) async {
+      final List<GoRoute> routes = <GoRoute>[
+        GoRoute(
+            path: '/',
+            builder: (_, __) {
+              return Builder(builder: (BuildContext context) {
+                return Text('1 ${GoRouterState.of(context).location}');
+              });
+            },
+            routes: <GoRoute>[
+              GoRoute(
+                  path: ':id',
+                  builder: (_, __) {
+                    return Builder(builder: (BuildContext context) {
+                      return Text(
+                          '2 ${GoRouterState.of(context).params['id']}');
+                    });
+                  }),
+            ]),
+      ];
+      final GoRouter router = await createRouter(routes, tester);
+      await tester.pumpAndSettle();
+      expect(find.text('1 /'), findsOneWidget);
+
+      router.go('/123');
+      await tester.pumpAndSettle();
+      expect(find.text('2 123'), findsOneWidget);
+      router.pop();
+      await tester.pump();
+      // Page 2 is in popping animation but should still be on screen with the
+      // correct path parameter.
+      expect(find.text('2 123'), findsOneWidget);
+    });
+
     testWidgets('registry retains GoRouterState for exiting route',
         (WidgetTester tester) async {
       final UniqueKey key = UniqueKey();