Nested navigation with Go_Router

Flutter tips Published on

Easy Nested Navigation in Flutter

Creating layouts where some parts of the screen navigate independently while others stay the same (like a sidebar or a bottom navigation bar) can be tricky.

Using Go_Router for Nested Layouts

Go_Router offers a great way to handle this with nested navigation. Instead of adding all your routes at the top level, you can group related routes together.

The Role of StatefulShellRoute

To manage the state for sections of your app that have their own navigation, you use StatefulShellRoute. This route acts as a wrapper for your sub-navigation structure, like a sidebar or tab view.

Organizing with StatefulShellBranch

Inside a StatefulShellRoute, you define different StatefulShellBranches. Each branch represents a distinct part of your navigation (e.g., one tab in a bottom nav bar, or one main section when using a sidebar).

Every StatefulShellBranch works like its own mini-navigator. This is a key point: each branch keeps its own navigation stack. So, if you navigate several screens deep in one branch, switch to another, and then come back, you'll return exactly where you left off in the first branch. Every main section keeps its history separate.

This makes building complex but intuitive navigation UIs in Flutter much simpler and more maintainable.

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

What is nested navigation?

It's a navigation pattern where parts of the screen navigate independently while other parts (like a sidebar or bottom bar) remain visible.

How does Go_Router handle nested navigation?

Go_Router uses `StatefulShellRoute` and `StatefulShellBranch` to group routes and manage independent navigation stacks.

What is a StatefulShellRoute?

It's a route in Go_Router used to wrap and manage the state for sections of the app with their own nested navigation.

What is a StatefulShellBranch?

It's a group of routes within a `StatefulShellRoute` that maintains its own independent navigation history.

Do branches remember where I was?

Yes, each `StatefulShellBranch` keeps its own navigation stack, so returning to a branch takes you back to the last screen you visited in that branch.

Read more
You may also be interested in
Pass text style efficiently to widgets  blog card image
Pass text style efficiently to widgets
Published on 2025-05-19T07:11:25.745Z
Flutter tips: how to create a responsive layout  blog card image
Flutter tips: how to create a responsive layout
Published on 2025-05-03
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved