Skip to content

Commit a99c7f5

Browse files
authored
[go_router] Fixes issue that path parameters are not set when using t… (flutter#6698)
�he goBranch. fixes flutter#129878
1 parent ae4dd32 commit a99c7f5

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
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+
## 14.1.2
2+
3+
- Fixes issue that path parameters are not set when using the `goBranch`.
4+
15
## 14.1.1
26

37
- Fixes correctness of the state provided in the `onExit`.

packages/go_router/lib/src/route.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,12 @@ class StatefulNavigationShell extends StatefulWidget {
11341134
/// Recursively traverses the routes of the provided StackedShellBranch to
11351135
/// find the first GoRoute, from which a full path will be derived.
11361136
final GoRoute route = branch.defaultRoute!;
1137-
return _router.configuration.locationForRoute(route)!;
1137+
final List<String> parameters = <String>[];
1138+
patternToRegExp(route.path, parameters);
1139+
assert(parameters.isEmpty);
1140+
final String fullPath = _router.configuration.locationForRoute(route)!;
1141+
return patternToPath(
1142+
fullPath, shellRouteContext.routerState.pathParameters);
11381143
}
11391144
}
11401145

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: 14.1.1
4+
version: 14.1.2
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,50 @@ void main() {
39563956
expect(statefulWidgetKey.currentState?.counter, equals(0));
39573957
});
39583958

3959+
testWidgets(
3960+
'Navigates to correct nested navigation tree in StatefulShellRoute '
3961+
'and maintains path parameters', (WidgetTester tester) async {
3962+
StatefulNavigationShell? routeState;
3963+
3964+
final List<RouteBase> routes = <RouteBase>[
3965+
GoRoute(
3966+
path: '/:id',
3967+
builder: (_, __) => const Placeholder(),
3968+
routes: <RouteBase>[
3969+
StatefulShellRoute.indexedStack(
3970+
builder: (BuildContext context, GoRouterState state,
3971+
StatefulNavigationShell navigationShell) {
3972+
routeState = navigationShell;
3973+
return navigationShell;
3974+
},
3975+
branches: <StatefulShellBranch>[
3976+
StatefulShellBranch(routes: <GoRoute>[
3977+
GoRoute(
3978+
path: 'a',
3979+
builder: (BuildContext context, GoRouterState state) =>
3980+
Text('a id is ${state.pathParameters['id']}'),
3981+
),
3982+
]),
3983+
StatefulShellBranch(routes: <GoRoute>[
3984+
GoRoute(
3985+
path: 'b',
3986+
builder: (BuildContext context, GoRouterState state) =>
3987+
Text('b id is ${state.pathParameters['id']}'),
3988+
),
3989+
]),
3990+
],
3991+
),
3992+
])
3993+
];
3994+
3995+
await createRouter(routes, tester, initialLocation: '/123/a');
3996+
expect(find.text('a id is 123'), findsOneWidget);
3997+
3998+
routeState!.goBranch(1);
3999+
await tester.pumpAndSettle();
4000+
expect(find.text('b id is 123'), findsOneWidget);
4001+
});
4002+
39594003
testWidgets('Maintains state for nested StatefulShellRoute',
39604004
(WidgetTester tester) async {
39614005
final GlobalKey<NavigatorState> rootNavigatorKey =

0 commit comments

Comments
 (0)