Repository navigation
Description
What package does this bug report belong to?
go_router
Summary
When a StatefulShellRoute branch redirects to a child route displayed on the root navigator, switching away and restoring the branch with goBranch() can omit the redirect page. The cached branch RouteMatchList contains the branch matches but still has the URI of the root-navigator child that was removed from those matches.
Steps to reproduce
- Configure two branches,
/aand/b, inStatefulShellRoute.indexedStack. - Redirect
/bto/b/welcome. Configurewelcomeas a child of/bwithparentNavigatorKeyset to the root navigator key. The redirect remains required on every entry. - Start at
/a, then select branch B usingnavigationShell.goBranch(1). The welcome page appears. - On the welcome page, cancel by calling
context.go('/a'). - Select branch B again using
navigationShell.goBranch(1)with the defaultinitialLocation: false.
Expected results
The welcome page appears again because the redirect condition has not changed. The restored branch cache should have a URI and path parameters consistent with its remaining route matches.
Actual results
On the second entry, the branch page is displayed without the welcome page. The cached list excludes the root-navigator child, but its URI still points to /b/welcome. The restore parser can therefore retain the cached list instead of the newly matched redirect destination.
Code sample
Save the following as test/branch_restore_test.dart in a Flutter project with go_router and flutter_test dependencies, then run flutter test test/branch_restore_test.dart.
This sample is supplied for upstream reproduction. It has not been executed against upstream 18.0.2 in this report; see the verification scope below.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
void main() {
testWidgets('root redirect page returns after branch restoration', (tester) async {
final rootKey = GlobalKey<NavigatorState>();
final router = GoRouter(
navigatorKey: rootKey,
initialLocation: '/a',
routes: [
StatefulShellRoute.indexedStack(
builder: (context, state, shell) => Scaffold(
body: shell,
bottomNavigationBar: Row(
children: [
TextButton(
onPressed: () => shell.goBranch(0),
child: const Text('Branch A'),
),
TextButton(
onPressed: () => shell.goBranch(1),
child: const Text('Branch B'),
),
],
),
),
branches: [
StatefulShellBranch(
routes: [
GoRoute(
path: '/a',
builder: (context, state) => const Center(child: Text('Page A')),
),
],
),
StatefulShellBranch(
routes: [
GoRoute(
path: '/b',
redirect: (context, state) =>
state.uri.path == '/b/welcome' ? null : '/b/welcome',
builder: (context, state) => const Center(child: Text('Page B')),
routes: [
GoRoute(
path: 'welcome',
parentNavigatorKey: rootKey,
builder: (context, state) => Scaffold(
body: Column(
children: [
const Text('Welcome'),
TextButton(
onPressed: () => context.go('/a'),
child: const Text('Cancel'),
),
],
),
),
),
],
),
],
),
],
),
],
);
addTearDown(router.dispose);
await tester.pumpWidget(MaterialApp.router(routerConfig: router));
await tester.pumpAndSettle();
await tester.tap(find.text('Branch B'));
await tester.pumpAndSettle();
expect(find.text('Welcome'), findsOneWidget);
await tester.tap(find.text('Cancel'));
await tester.pumpAndSettle();
expect(find.text('Page A'), findsOneWidget);
await tester.tap(find.text('Branch B'));
await tester.pumpAndSettle();
expect(find.text('Welcome'), findsOneWidget);
expect(router.routerDelegate.currentConfiguration.uri.path, '/b/welcome');
expect(tester.takeException(), isNull);
});
}Source analysis
The relevant upstream code was inspected at flutter/packages commit 3b733d27c63cf7b6012e99afacd267d3a24de5a3, whose go_router/pubspec.yaml declares version 18.0.2.
_scopedMatchList()usesmatchList.copyWith(matches: _scopeMatches(matchList.matches))._scopeMatches()discards matches following the current shell, including the root-navigator child in this scenario.RouteMatchList.copyWith()retains the previousuriandpathParameterswhen they are not supplied. The resulting list therefore has inconsistent matches and location metadata.goBranch()restores this cached list.- In
NavigatingType.restore, when the cached and newly matched URIs are equal, the parser returns the cached list. Here both URIs are/b/welcome, but the cached list lacks the welcome match.
Candidate fix and regression coverage
RouteMatchList.remove() already updates the URI path and removes obsolete path parameters when the remaining full path changes. Scoping the branch by removing excluded matches through this API, rather than replacing only matches, is a candidate fix.
A public fork PR contains this approach and regression tests: denihero/packages#1. That PR targets a fork, was closed without merge, and does not constitute an upstream fix. Its test suite includes repeated cancellation/re-entry, root-popup URI cleanup, branch path parameters, and preservation of imperative/declarative branch stacks. Any test results reported there apply to that fork, not to upstream 18.0.2.
Verification scope and environment
- The original behavior was reported in the fork scenario linked above.
- Current upstream source inspection confirms that the same scoping/copy/restore path remains at the pinned commit.
- Upstream runtime reproduction and the sample test above have not been run for this report. No claim of a test failure or successful fix on upstream 18.0.2 is made.
- Platform-specific confirmation, a dependency lockfile, and Flutter Doctor output for an upstream reproduction are not yet available.
Related report
#158238 also reports a branch restoration/navigation mismatch, but its sample uses pop() followed by go() and does not use a root-navigator child redirect. This report isolates the inconsistent cached URI produced by branch scoping.
Activity
AyatAliev commentedon Oct 12, 2026
Proposed fix: flutter/packages#13735. It continues flutter/packages#13202, which was closed after I accidentally deleted my fork; the review discussion is there.
suryaKommana2662 commentedon Oct 13, 2026
@AyatAliev I was able to reproduce the reported behavior locally using the provided test with
flutter test test/branch_restore_test.dart.go_router: ^18.0.2The test failed with the following output:
I also noticed the proposed fix in flutter/packages#13202. routing this to the
team-ecosystemfor further investigationFlutter Doctor Output
test: guard a tab redirect on every entry (flutter/flutter#194209)