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

- Secured canPop method for the lack of matches in routerDelegate's configuration.

## 14.8.0

- Adds `preload` parameter to `StatefulShellBranchData.$branch`.
Expand Down
3 changes: 3 additions & 0 deletions packages/go_router/lib/src/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList>
if (navigatorKey.currentState?.canPop() ?? false) {
return true;
}
if (currentConfiguration.matches.isEmpty) {
return false;
}
RouteMatchBase walker = currentConfiguration.matches.last;
while (walker is ShellRouteMatch) {
if (walker.navigatorKey.currentState?.canPop() ?? false) {
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.8.0
version: 14.8.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
14 changes: 14 additions & 0 deletions packages/go_router/test/delegate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ void main() {
expect(goRouter.routerDelegate.canPop(), true);
},
);
testWidgets(
'It should return false if there are no matches in the stack',
(WidgetTester tester) async {
final GoRouter goRouter = GoRouter(
initialLocation: '/',
routes: <GoRoute>[],
);
addTearDown(goRouter.dispose);
await tester.pumpWidget(MaterialApp.router(routerConfig: goRouter));
await tester.pumpAndSettle();
expect(goRouter.routerDelegate.currentConfiguration.matches.length, 0);
expect(goRouter.routerDelegate.canPop(), false);
},
);
});

group('pushReplacement', () {
Expand Down