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 @@
## 14.1.2

- Fixes issue that path parameters are not set when using the `goBranch`.

## 14.1.1

- Fixes correctness of the state provided in the `onExit`.
Expand Down
7 changes: 6 additions & 1 deletion packages/go_router/lib/src/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,12 @@ class StatefulNavigationShell extends StatefulWidget {
/// Recursively traverses the routes of the provided StackedShellBranch to
/// find the first GoRoute, from which a full path will be derived.
final GoRoute route = branch.defaultRoute!;
return _router.configuration.locationForRoute(route)!;
final List<String> parameters = <String>[];
patternToRegExp(route.path, parameters);
assert(parameters.isEmpty);
final String fullPath = _router.configuration.locationForRoute(route)!;
return patternToPath(
fullPath, shellRouteContext.routerState.pathParameters);
}
}

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: 14.1.1
version: 14.1.2
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
44 changes: 44 additions & 0 deletions packages/go_router/test/go_router_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3956,6 +3956,50 @@ void main() {
expect(statefulWidgetKey.currentState?.counter, equals(0));
});

testWidgets(
'Navigates to correct nested navigation tree in StatefulShellRoute '
'and maintains path parameters', (WidgetTester tester) async {
StatefulNavigationShell? routeState;

final List<RouteBase> routes = <RouteBase>[
GoRoute(
path: '/:id',
builder: (_, __) => const Placeholder(),
routes: <RouteBase>[
StatefulShellRoute.indexedStack(
builder: (BuildContext context, GoRouterState state,
StatefulNavigationShell navigationShell) {
routeState = navigationShell;
return navigationShell;
},
branches: <StatefulShellBranch>[
StatefulShellBranch(routes: <GoRoute>[
GoRoute(
path: 'a',
builder: (BuildContext context, GoRouterState state) =>
Text('a id is ${state.pathParameters['id']}'),
),
]),
StatefulShellBranch(routes: <GoRoute>[
GoRoute(
path: 'b',
builder: (BuildContext context, GoRouterState state) =>
Text('b id is ${state.pathParameters['id']}'),
),
]),
],
),
])
];

await createRouter(routes, tester, initialLocation: '/123/a');
expect(find.text('a id is 123'), findsOneWidget);

routeState!.goBranch(1);
await tester.pumpAndSettle();
expect(find.text('b id is 123'), findsOneWidget);
});

testWidgets('Maintains state for nested StatefulShellRoute',
(WidgetTester tester) async {
final GlobalKey<NavigatorState> rootNavigatorKey =
Expand Down