Skip to content

Commit 6cc2fc4

Browse files
[go_router] Resolves #5113 (comment)
1 parent 795f7c0 commit 6cc2fc4

File tree

5 files changed

+46
-31
lines changed

5 files changed

+46
-31
lines changed

packages/go_router/lib/src/configuration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ class RouteConfiguration {
315315
List<RouteMatch>? _getLocRouteMatches(
316316
Uri uri, Map<String, String> pathParameters) {
317317
final List<RouteMatch>? result = _getLocRouteRecursively(
318-
location: uri.path.isEmpty ? '/' : uri.path,
319-
remainingLocation: uri.path.isEmpty ? '/' : uri.path,
318+
location: uri.path,
319+
remainingLocation: uri.path,
320320
matchedLocation: '',
321321
matchedPath: '',
322322
pathParameters: pathParameters,

packages/go_router/lib/src/router.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,10 @@ class GoRouter implements RouterConfig<RouteMatchList> {
526526
// verified by assert() during the initialization.
527527
return initialLocation!;
528528
}
529+
final Uri platformDefaultUri =
530+
Uri.parse(WidgetsBinding.instance.platformDispatcher.defaultRouteName);
529531
final String platformDefault =
530-
WidgetsBinding.instance.platformDispatcher.defaultRouteName;
532+
platformDefaultUri.path.isEmpty ? '/' : platformDefaultUri.path;
531533
if (initialLocation == null) {
532534
return platformDefault;
533535
} else if (platformDefault == '/') {

packages/go_router/test/go_router_test.dart

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,8 +2445,8 @@ void main() {
24452445
// https://github.com/flutter/flutter/issues/124045.
24462446
// ignore: deprecated_member_use
24472447
expect(router.routeInformationProvider.value.location, '/dummy');
2448-
TestWidgetsFlutterBinding
2449-
.instance.platformDispatcher.defaultRouteNameTestValue = '/';
2448+
TestWidgetsFlutterBinding.instance.platformDispatcher
2449+
.clearDefaultRouteNameTestValue();
24502450
});
24512451

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

2469+
group('_effectiveInitialLocation()', () {
2470+
final List<GoRoute> routes = <GoRoute>[
2471+
GoRoute(
2472+
path: '/',
2473+
builder: (BuildContext context, GoRouterState state) =>
2474+
const HomeScreen(),
2475+
),
2476+
];
2477+
2478+
testWidgets(
2479+
'When platformDispatcher.defaultRouteName is deep-link Uri with '
2480+
'scheme, authority, no path', (WidgetTester tester) async {
2481+
TestWidgetsFlutterBinding.instance.platformDispatcher
2482+
.defaultRouteNameTestValue = 'https://domain.com';
2483+
final GoRouter router = await createRouter(
2484+
routes,
2485+
tester,
2486+
);
2487+
expect(router.routeInformationProvider.value.uri.path, '/');
2488+
TestWidgetsFlutterBinding.instance.platformDispatcher
2489+
.clearDefaultRouteNameTestValue();
2490+
});
2491+
2492+
testWidgets(
2493+
'When platformDispatcher.defaultRouteName is deep-link Uri with '
2494+
'scheme, authority, no path, but trailing slash',
2495+
(WidgetTester tester) async {
2496+
TestWidgetsFlutterBinding.instance.platformDispatcher
2497+
.defaultRouteNameTestValue = 'https://domain.com/';
2498+
final GoRouter router = await createRouter(
2499+
routes,
2500+
tester,
2501+
);
2502+
expect(router.routeInformationProvider.value.uri.path, '/');
2503+
TestWidgetsFlutterBinding.instance.platformDispatcher
2504+
.clearDefaultRouteNameTestValue();
2505+
});
2506+
});
2507+
24692508
group('params', () {
24702509
testWidgets('preserve path param case', (WidgetTester tester) async {
24712510
final List<GoRoute> routes = <GoRoute>[

packages/go_router/test/matching_test.dart

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,4 @@ void main() {
107107
expect(decoded, isNotNull);
108108
expect(decoded, equals(list1));
109109
});
110-
111-
test('RouteMatchList for deep-link Uri with scheme, authority', () {
112-
final RouteConfiguration configuration = RouteConfiguration(
113-
routes: <GoRoute>[
114-
GoRoute(
115-
path: '/',
116-
builder: (BuildContext context, GoRouterState state) =>
117-
const Placeholder(),
118-
),
119-
],
120-
redirectLimit: 0,
121-
navigatorKey: GlobalKey<NavigatorState>(),
122-
topRedirect: (_, __) => null,
123-
);
124-
125-
final RouteMatchList matchList1 = configuration.findMatch('/');
126-
expect(matchList1.matches[0].matchedLocation, '/');
127-
final RouteMatchList matchList2 =
128-
configuration.findMatch('https://domain.com');
129-
expect(matchList2.matches[0].matchedLocation, '/');
130-
final RouteMatchList matchList3 =
131-
configuration.findMatch('https://domain.com/');
132-
expect(matchList3.matches[0].matchedLocation, '/');
133-
});
134110
}

packages/go_router/test/path_utils_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ void main() {
100100
verify('/a/', '/a');
101101
verify('/', '/');
102102
verify('/a/b/', '/a/b');
103-
verify('scheme://authority', 'scheme://authority');
104-
verify('scheme://authority/', 'scheme://authority');
105103

106104
expect(() => canonicalUri('::::'), throwsA(isA<FormatException>()));
107105
expect(() => canonicalUri(''), throwsA(anything));

0 commit comments

Comments
 (0)