Skip to content

Commit

Permalink
[go_router] Retain query parameter during refresh and first redirect (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinVignal authored Nov 9, 2023
1 parent 7a2973a commit 5929d66
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 12.1.1

- Retains query parameters during refresh and first redirect.

## 12.1.0

- Adds an ability to add a custom codec for serializing/deserializing extra.
Expand Down
16 changes: 12 additions & 4 deletions packages/go_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,18 @@ class GoRouter implements RouterConfig<RouteMatchList> {
// verified by assert() during the initialization.
return initialLocation!;
}
final Uri platformDefaultUri =
Uri.parse(WidgetsBinding.instance.platformDispatcher.defaultRouteName);
final String platformDefault =
platformDefaultUri.path.isEmpty ? '/' : platformDefaultUri.path;
Uri platformDefaultUri = Uri.parse(
WidgetsBinding.instance.platformDispatcher.defaultRouteName,
);
if (platformDefaultUri.hasEmptyPath) {
// TODO(chunhtai): Clean up this once `RouteInformation.uri` is available
// in packages repo.
platformDefaultUri = Uri(
path: '/',
queryParameters: platformDefaultUri.queryParameters,
);
}
final String platformDefault = platformDefaultUri.toString();
if (initialLocation == null) {
return platformDefault;
} else if (platformDefault == '/') {
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: 12.1.0
version: 12.1.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
15 changes: 15 additions & 0 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,21 @@ void main() {
TestWidgetsFlutterBinding.instance.platformDispatcher
.clearDefaultRouteNameTestValue();
});

testWidgets(
'When platformDispatcher.defaultRouteName is deep-link Uri with '
'scheme, authority, no path, and query parameters',
(WidgetTester tester) async {
TestWidgetsFlutterBinding.instance.platformDispatcher
.defaultRouteNameTestValue = 'https://domain.com?param=1';
final GoRouter router = await createRouter(
routes,
tester,
);
expect(router.routeInformationProvider.value.uri.toString(), '/?param=1');
TestWidgetsFlutterBinding.instance.platformDispatcher
.clearDefaultRouteNameTestValue();
});
});

group('params', () {
Expand Down

0 comments on commit 5929d66

Please sign in to comment.