Skip to content

Commit 8ac5729

Browse files
authored
[go_router] Fixes namedLocation to return URIs without trailing question marks if there are no query parameters. (#2471)
1 parent fb0bbcc commit 8ac5729

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
## NEXT
1+
## 4.2.8
22

3-
- Cleans up examples
3+
- Fixes namedLocation to return URIs without trailing question marks if there are no query parameters.
4+
- Cleans up examples.
45

56
## 4.2.7
67

7-
- Update README
8+
- Updates README.
89

910
## 4.2.6
1011

packages/go_router/lib/src/configuration.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ class RouteConfiguration {
8080
param.key: Uri.encodeComponent(param.value)
8181
};
8282
final String location = patternToPath(path, encodedParams);
83-
return Uri(path: location, queryParameters: queryParams).toString();
83+
return Uri(
84+
path: location,
85+
queryParameters: queryParams.isEmpty ? null : queryParams)
86+
.toString();
8487
}
8588

8689
@override

packages/go_router/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 4.2.7
4+
version: 4.2.8
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

packages/go_router/test/parser_test.dart

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,26 @@ void main() {
9292
topRedirect: (_) => null,
9393
);
9494

95-
expect(configuration.namedLocation('lowercase'), '/abc?');
96-
expect(configuration.namedLocation('LOWERCASE'), '/abc?');
97-
expect(configuration.namedLocation('camelCase'), '/efg?');
98-
expect(configuration.namedLocation('camelcase'), '/efg?');
99-
expect(configuration.namedLocation('snake_case'), '/hij?');
100-
expect(configuration.namedLocation('SNAKE_CASE'), '/hij?');
95+
expect(configuration.namedLocation('lowercase'), '/abc');
96+
expect(configuration.namedLocation('LOWERCASE'), '/abc');
97+
expect(configuration.namedLocation('camelCase'), '/efg');
98+
expect(configuration.namedLocation('camelcase'), '/efg');
99+
expect(configuration.namedLocation('snake_case'), '/hij');
100+
expect(configuration.namedLocation('SNAKE_CASE'), '/hij');
101+
102+
// With query parameters
103+
expect(
104+
configuration
105+
.namedLocation('lowercase', queryParams: const <String, String>{}),
106+
'/abc');
107+
expect(
108+
configuration.namedLocation('lowercase',
109+
queryParams: const <String, String>{'q': '1'}),
110+
'/abc?q=1');
111+
expect(
112+
configuration.namedLocation('lowercase',
113+
queryParams: const <String, String>{'q': '1', 'g': '2'}),
114+
'/abc?q=1&g=2');
101115
});
102116

103117
test('GoRouteInformationParser returns error when unknown route', () async {

0 commit comments

Comments
 (0)