Skip to content

Commit a7a5ec8

Browse files
authored
[go_router] Fix Android Cold Start deep link with empty path losing scheme and authority. (#9868)
### Description Fixes an issue where deep links with empty paths (e.g., `https://example.com`) lose their scheme and authority information during Android Cold Start. This PR fixes flutter/flutter#174249 Detailed reproduction steps, environment information, and code sample are provided in the linked issue. ### Problem On Android Cold Start, if the initial deep link has no path (`https://example.com`), `_effectiveInitialLocation` incorrectly creates a new `Uri` with only `/?` instead of preserving scheme and authority. This results in the router receiving a relative path instead of the full deep link URL. ### Solution Use `Uri.replace(path: '/')` instead of creating a new `Uri`, so that the original scheme and authority are preserved. ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 51df718 commit a7a5ec8

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 16.2.4
2+
3+
- Fix Android Cold Start deep link with empty path losing scheme and authority.
4+
15
## 16.2.3
26

37
- Fixes an issue where iOS back gesture pops entire ShellRoute instead of the active sub-route.

packages/go_router/lib/src/router.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,12 +574,7 @@ class GoRouter implements RouterConfig<RouteMatchList> {
574574
WidgetsBinding.instance.platformDispatcher.defaultRouteName,
575575
);
576576
if (platformDefaultUri.hasEmptyPath) {
577-
// TODO(chunhtai): Clean up this once `RouteInformation.uri` is available
578-
// in packages repo.
579-
platformDefaultUri = Uri(
580-
path: '/',
581-
queryParameters: platformDefaultUri.queryParameters,
582-
);
577+
platformDefaultUri = platformDefaultUri.replace(path: '/');
583578
}
584579
final String platformDefault = platformDefaultUri.toString();
585580
if (initialLocation == null) {

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: 16.2.3
4+
version: 16.2.4
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/go_router_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3371,7 +3371,7 @@ void main() {
33713371
final GoRouter router = await createRouter(routes, tester);
33723372
expect(
33733373
router.routeInformationProvider.value.uri.toString(),
3374-
'/?param=1',
3374+
'https://domain.com/?param=1',
33753375
);
33763376
TestWidgetsFlutterBinding.instance.platformDispatcher
33773377
.clearDefaultRouteNameTestValue();

0 commit comments

Comments
 (0)