Flutter › Named Routes & Navigator 2.0 (Router API)
How do you properly implement nested navigation using a considerably more complex router structure, such as one genuinely needed to properly support a bottom navigation bar where each individual tab genuinely maintains its own entirely separate independent navigation stack?
IntermediateAnswer
Implementing nested navigation typically involves defining a genuinely separate distinct Navigator specifically for each individual tab within a bottom navigation bar, each maintaining its own entirely separate independent stack of screens, while a single shared outer Navigator manages switching between those particular separate tabs themselves, and go_router genuinely supports this exact same particular pattern through its own dedicated StatefulShellRoute, letting each individual tab genuinely properly preserve its own separate specific navigation history even as a user actually switches back and forth between several genuinely different tabs.
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) => ScaffoldWithNavBar(navigationShell: navigationShell),
branches: [homeBranch, searchBranch, profileBranch],
)Real-world example A social media app uses go_router's StatefulShellRoute to properly maintain each individual bottom tab's own entirely separate navigation history, correctly ensuring a user who navigates deep into their profile tab and then briefly switches over to the home tab still finds their profile tab exactly where they had genuinely previously left it upon returning.