Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions packages/go_router/lib/src/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> with ChangeNotifie
return true; // Return true if maybePop handled the pop
}
}

if (currentConfiguration.matches.isEmpty) {
return false;
}
Comment thread
abhaysaqi marked this conversation as resolved.
Outdated
// Fallback to onExit if maybePop did not handle the pop
final GoRoute lastRoute = currentConfiguration.last.route;
if (lastRoute.onExit != null && navigatorKey.currentContext != null) {
Expand Down Expand Up @@ -115,7 +117,9 @@ class GoRouterDelegate extends RouterDelegate<RouteMatchList> with ChangeNotifie
// Set state directly without canPop check
states.add(navigatorKey.currentState!);
}

if (currentConfiguration.matches.isEmpty) {
return states.reversed;
}
Comment thread
abhaysaqi marked this conversation as resolved.
Outdated
Comment thread
abhaysaqi marked this conversation as resolved.
Outdated
RouteMatchBase walker = currentConfiguration.matches.last;
while (walker is ShellRouteMatch) {
final NavigatorState potentialCandidate = walker.navigatorKey.currentState!;
Expand Down
17 changes: 17 additions & 0 deletions packages/go_router/test/delegate_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@ void main() {
});
});

testWidgets('popRoute does not throw Bad state when currentConfiguration is empty', (
WidgetTester tester,
) async {
final GoRouter goRouter = GoRouter(
initialLocation: '/',
routes: <GoRoute>[GoRoute(path: '/', builder: (_, _) => const DummyStatefulWidget())],
);
addTearDown(goRouter.dispose);
await tester.pumpWidget(MaterialApp.router(routerConfig: goRouter));

// Simulate empty configuration (e.g. startup window before first route resolves)
goRouter.routerDelegate.currentConfiguration = RouteMatchList.empty;

// Should return false without throwing "Bad state: No element"
expect(await goRouter.routerDelegate.popRoute(), isFalse);
});

group('push', () {
testWidgets('It should return different pageKey when push is called', (
WidgetTester tester,
Expand Down