zakariaf/flutter-skills/navigation-and-routing
Claude Code and agent skill by zakariaf/flutter-skills
- community
Checking that the SKILL.md file is still in the repository.
Enforces one app-wide GoRouter in lib/routing/ wired via MaterialApp.router, deep-linkable identity in path params never state.extra, context.go-vs-context.push discipline, redirect guards as pure functions driven by a Riverpod refreshListenable, StatefulShellRoute.indexedStack for branch-state-preserving BottomNavigationBar/NavigationRail shells, CustomTransitionPage transitions that respect reduced motion, PopScope (canPop/onPopInvokedWithResult) for unsaved-changes interception, and an errorBuilder 404 route. Use when adding routes, GoRoute, redirect, auth/onboarding gates, deep links, ShellRoute or nested navigation, bottom-nav/rail tab shells, page transitions, back-button/unsaved-changes handling, notification-payload-to-location mapping, typed routes, go_router_builder, or wiring go_router into app.dart.
Install
npx vskill@latest install zakariaf/flutter-skills/navigation-and-routingSKILL.md
The same SKILL.md was published earlier as zakariaf/flutter-skills/navigation-and-routing.
Navigation and routing
This skill owns app navigation with go_router. There is exactly ONE GoRouter for the app, defined in lib/routing/, and every screen is reachable by a URL. Navigation is a data structure (routes + a pure redirect), not a pile of imperative Navigator.push calls.
Read the reference for the task at hand:
references/go-router-config.md— the single router,context.govscontext.push, path params vsstate.extra, typed route helpers,errorBuilder/404.references/guards-and-redirects.md— pureredirectfunctions, the RiverpodrefreshListenable, auth + onboarding gates, avoiding redirect loops.references/shells-and-deep-links.md—StatefulShellRoute.indexedStackfor bottom-nav/rail shells,CustomTransitionPage,PopScope, and notification-payload → location mapping.
Run scripts/check_routing.sh before a PR.
Non-negotiable rules
- Exactly ONE `GoRouter`, built in `lib/routing/`, wired once via `MaterialApp.router` in `app.dart`. Multiple routers fragment history, deep links, and back-button behaviour. The router is created behind a provider so guards can watch app state.
- Deep-linkable identity lives in PATH PARAMS, never in `state.extra`.
extrais a live Dart object: it isnullon a cold start from a deep link and after process death / restoration. A screen that needs an id to rebuild must read it fromstate.pathParametersso the URL alone fully reconstructs the screen. - `state.extra` is ONLY an optional non-identity optimisation (a pre-fetched object to avoid a reload flash). The screen must still work — refetch by id — when
extraisnull. - Use `context.go` to replace the stack (declarative destinations, tabs, post-login home); use `context.push` to stack a screen you expect to pop back from (a detail, a modal flow). Mixing them wrong breaks the back button. Know which one every call site needs.
- Guards are PURE `redirect` functions.
redirectreturns a new locationString?(ornullto allow) fromGoRouterState+ a snapshot of app state. No I/O, no navigation calls, no side effects insideredirect— it runs on every navigation and can run repeatedly. - Reactive guards use a `refreshListenable`, not polling. Bridge the Riverpod auth/onboarding provider to a
Listenable; the router re-evaluatesredirectwhenever it fires. Seestate-management-riverpod. - Redirects must be loop-free. Always allow the destination the guard sends you TO (e.g. never redirect
/sign-inback to/sign-in). Guard againstA→B→Aby checking the current location before redirecting. - Tab/branch shells use `StatefulShellRoute.indexedStack`. It preserves each branch's navigation stack and state across tab switches; a plain
ShellRoutewith anIndexedStackyou wire by hand does not survive router rebuilds as cleanly. Switch branches withnavigationShell.goBranch(index). - Custom transitions go through `CustomTransitionPage` and respect reduced motion. When the platform requests reduced motion, collapse to a no-op/fade. Read the flag from
MediaQuery, resolve motion via the design system — seeaccessibility-as-codeanddesign-system-structure. - Intercept back / unsaved changes with `PopScope`, not `WillPopScope` (removed). Set
canPop: falseand handle inonPopInvokedWithResult(bool didPop, T? result); only navigate away after the user confirms. - Provide an `errorBuilder` and a real 404/error route. An unmatched deep link must land on a designed error screen, never a red error box.
- Never hold a `BuildContext` across an `await` before navigating. Capture
GoRouter.of(context)(or the router) before the await, or guard withcontext.mountedafter. Seeasync-safety. - A feature does not build its own router.
scaffold-feature-moduleregisters a feature'sGoRouteINTO this router's route list; features never instantiateGoRouter.
The single router
app.dart reads the router from a provider and hands it to MaterialApp.router. The router itself lives in routing/ and is the only place GoRouter(...) is constructed.
Identity in the path, not in extra
Typed route helpers (constants, not string soup)
Prefer small constant/builder classes so call sites never hand-concatenate paths. go_router_builder codegen is an OPTIONAL upgrade, not the default.
go vs push
Anti-patterns
- Two
GoRouterinstances, or a nestedNavigator/MaterialAppinside a screen for "sub-navigation." Use nested routes /StatefulShellRoute. - Passing a domain id through
state.extraand readingextra!inbuild— crashes on cold start. - I/O,
ref.readof async work, or callingcontext.goINSIDEredirect. Redirect is pure and returns a location. - A
redirectthat can bounce forever because it also redirects its own target. - Mixing
Navigator.pushNamed('/x')string routes with go_router — one navigation system only. WillPopScope(removed) instead ofPopScope.- Awaiting then using the same
contextto navigate without amountedcheck. - A feature package/folder constructing its own
GoRouter.
Definition of done
- One
GoRouterinlib/routing/, oneMaterialApp.routerinapp.dart. - Every screen reachable by a URL; every id-bearing screen reads its id from
state.pathParameters. state.extrais only ever an optional optimisation; every such screen renders correctly withextra == null.- Guards are pure
redirectfunctions with arefreshListenable; no redirect loops. - Tab shells use
StatefulShellRoute.indexedStack; branch state survives tab switches. - Transitions respect reduced motion;
errorBuilder+ 404 route present. PopScopeguards unsaved changes; noBuildContextused across an await when navigating.scripts/check_routing.shpasses.
Related skills
app-startup-and-bootstrap— ownsmain()/bootstrap()ordering and whereMaterialApp.routeris mounted.state-management-riverpod— the auth/onboarding providers therefreshListenablebridges.scaffold-feature-module— registers a featureGoRouteinto this router.adaptive-layout— choosesNavigationRailvsBottomNavigationBarby width for the shell.accessibility-as-code— reduced-motion flag and semantics for navigation.design-system-structure— the reduced-motion token /resolveMotionhelper for transitions.async-safety—BuildContext/mountedrules around awaited navigation.local-notifications-scheduler— the notification payload whose pure mapper produces a location.
References
- go_router package: https://pub.dev/packages/go_router
- go_router API docs: https://pub.dev/documentation/go_router/latest/
- Flutter navigation & routing: https://docs.flutter.dev/ui/navigation
- Deep linking: https://docs.flutter.dev/ui/navigation/deep-linking
- PopScope API: https://api.flutter.dev/flutter/widgets/PopScope-class.html
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/navigation-and-routing/SKILL.md
Popularity
- Repository stars
- 22
- Repository forks
- 4
- 7-day trend score
- 16
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/zakariaf/flutter-skills/navigation-and-routing)