Skip to content
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
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.0.1

- Fixes deep-link with no path on cold start.

## 12.0.0

- Adds ability to dynamically update routing table.
Expand Down
3 changes: 3 additions & 0 deletions packages/go_router/lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
initialMatches =
// TODO(chunhtai): remove this ignore and migrate the code
// https://github.com/flutter/flutter/issues/124045.
// TODO(chunhtai): After the migration from routeInformation's location
// to uri, empty path check might be required here; see
// https://github.com/flutter/packages/pull/5113#discussion_r1374861070
// ignore: deprecated_member_use, unnecessary_non_null_assertion
configuration.findMatch(routeInformation.location!, extra: state.extra);
if (initialMatches.isError) {
Expand Down
4 changes: 3 additions & 1 deletion packages/go_router/lib/src/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,10 @@ 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 =
WidgetsBinding.instance.platformDispatcher.defaultRouteName;
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the deeplink is called when the app is already running? wasn't the path be missing in that case? I think you need to also modify the logic in _platformReportsNewRouteInformation

Copy link
Contributor Author

@hrishikesh-kadam hrishikesh-kadam Oct 27, 2023

Choose a reason for hiding this comment

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

For now, the change is not required because the RouteInformation.location getter in _platformReportsNewRouteInformation() handles the empty path.

Once the package maintainers decide to migrate from RouteInformation.location to RouteInformation.uri, then it would be the right time to edit.
Also, the care should be taken about where to strip the scheme and authority, either early or late in the code as mentioned in this comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah interesting, thanks for reminding. Can you add a todo somewhere to remind us about location to uri migration? That way we won't break the code when that happens

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.

platformDefaultUri.path.isEmpty ? '/' : platformDefaultUri.path;
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.0.0
version: 12.0.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
43 changes: 41 additions & 2 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2445,8 +2445,8 @@ void main() {
// https://github.com/flutter/flutter/issues/124045.
// ignore: deprecated_member_use
expect(router.routeInformationProvider.value.location, '/dummy');
TestWidgetsFlutterBinding
.instance.platformDispatcher.defaultRouteNameTestValue = '/';
TestWidgetsFlutterBinding.instance.platformDispatcher
.clearDefaultRouteNameTestValue();
});

test('throws assertion if initialExtra is set w/o initialLocation', () {
Expand All @@ -2466,6 +2466,45 @@ void main() {
});
});

group('_effectiveInitialLocation()', () {
final List<GoRoute> routes = <GoRoute>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen(),
),
];

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

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

group('params', () {
testWidgets('preserve path param case', (WidgetTester tester) async {
final List<GoRoute> routes = <GoRoute>[
Expand Down