Flutter · One codebase, native feel
How do navigation and routing work in Flutter?
Short answer
Navigator manages a stack of routes. For declarative routing and deep links, use Router with a package such as go_router, which maps URLs to screens and supports guards and nested shells.
Navigator 1.0 is imperative: push and pop routes on a stack. That works for simple flows but becomes hard to test and to map to URLs. Router 2.0 exposes a declarative route configuration driven by the platform route information, which is what go_router builds on.
onPressed: () async {
final saved = await Navigator.of(context).push<bool>(
MaterialPageRoute(builder: (_) => const CheckoutPage()),
);
if (!context.mounted) return;
if (saved == true) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Order placed')),
);
}
}- Push returns a Future with the value passed to pop
- Named routes are simple but become inflexible as parameters and guards grow
- go_router supports path parameters, query parameters, redirects and nested shells
- StatefulShellRoute preserves independent navigation stacks per tab
- Route guards belong in redirect logic, not scattered across button handlers
What I check in review
Deep links must land on the right screen with valid arguments and a working back stack. Authentication redirects must avoid loops. Dialogs and bottom sheets are not pages and should not be pushed as routes unless they are genuinely addressable. Passing complex objects through route extra is risky because the route may be restored without them.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1When would you still use Navigator directly?
- 2How do redirect guards avoid infinite loops?
- 3What is the difference between path and query parameters?
- 4How do you preserve tab navigation stacks?
Say it in the interview
Navigator pushes routes on a stack and returns results through pop. For anything with deep links or complex flows I use go_router, because routes are declared from URLs and can carry redirect guards and nested shells. The important part is that any route reachable by a link can build itself from an id. I also keep tab stacks independent when the product expects that.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Flutter mock interview and get scored feedback on depth, clarity and confidence.