GoRouter.dev

Current field guide · 2026

Give every tab its own journey

Use StatefulShellRoute when parallel destinations need independent navigation histories and retained branch state.

Edition published 21 Oct 2026go_router 18.1.1 reference
On this page

Choose the kind of shell

ShellRoute wraps matching content in a persistent frame. StatefulShellRoute goes further by providing separate Navigators for its branches. Its indexedStack constructor supplies the standard branch-container behavior.

Keep the shell outside the branch

Your shell widget renders the supplied StatefulNavigationShell and uses its currentIndex for the selected navigation item. Call goBranch to switch the active branch rather than manually rebuilding all tab screens.

Decide what reselection means

Tapping an already active tab can preserve its current detail or return to its initial location. Specify that behavior intentionally. Test whether scroll positions, form state, and detail stacks match what users expect.

Test a direct child URL

A browser can open a nested tab destination before any tab has been selected. The route map should select the correct branch and build a useful shell. State restoration across process death is a further concern; retained branch state within a running session does not automatically solve it.

dart / example
StatefulShellRoute.indexedStack(
  builder: (context, state, navigationShell) => AppShell(
    navigationShell: navigationShell,
  ),
  branches: [
    StatefulShellBranch(routes: [
      GoRoute(path: '/books', builder: (_, __) => const Books()),
    ]),
    StatefulShellBranch(routes: [
      GoRoute(path: '/saved', builder: (_, __) => const Saved()),
    ]),
  ],
)
Earlier edition: read the complete original guide. Its older APIs are kept in historical context.

Sources & version context

GoRouter.dev documentation edition. Examples illustrate the APIs described in the linked primary documentation. Adapt application-owned widgets and services to your project. They are not an executed Flutter session in this browser.

Verify that each tab restores its own navigation stack

Use one StatefulShellBranch per tab under StatefulShellRoute.indexedStack. Put the shell in the scaffold body and connect destination selection to shell.goBranch(index).

  1. Set branch A to /library and branch B to /saved. Give each a child, /library/book/:id and /saved/note/:id.
  2. Open book 42 in Library. Switch to Saved and open note 7. Return to Library and check that book 42 is still visible.
  3. Switch back to Saved and pop note 7. Confirm Saved returns to its root. Switch to Library and verify book 42 is still open.

Expected sequence: Library → Book 42 → Saved → Note 7 → Book 42 → Note 7 → Saved → Book 42. This example uses go_router 18.1.1. For a separate reset-on-reselect behaviour, explicitly test goBranch with initialLocation enabled.

Library: book 42 → Saved: note 7 → Each stack resumes
Switching branches resumes each stack. A pop affects the active branch in this example.

go_router 18.1.1 · Configuration

Find your next route