Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,7 +24,7 @@

## 6.2.0

- Export supertypes in route_data.dart library
- Exports supertypes in route_data.dart library.

## 6.1.0

Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class RouteBuilder {
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,
Expand Down
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
35 changes: 35 additions & 0 deletions packages/go_router/test/go_router_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,41 @@ void main() {
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why it's still at page 2 after poping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment to explain.

});

testWidgets('registry retains GoRouterState for exiting route',
(WidgetTester tester) async {
final UniqueKey key = UniqueKey();
Expand Down