πŸ›€οΈ

GoRouter Declarative Routing

Flutter Official Recommended Routing Package

go_router is a declarative routing package officially maintained by the Flutter team.

Define routes with GoRoute objects and register them in a GoRouter instance. Navigate with context.go('/home'), mapping 1:1 with URL paths.

Supports all practical features: auth redirects (redirect to /login when not logged in), ShellRoute (persistent bottom tab bar), nested routes, etc.

Implementation Steps

1

Add go_router package (pubspec.yaml)

2

Create GoRouter instance + define routes with GoRoute

3

Connect router with MaterialApp.router()

4

Implement auth guard with redirect callback

Pros

  • Perfect Web/deep link support with URL-based routing
  • Stability guaranteed by Flutter team official maintenance

Cons

  • Initial setup more complex than basic Navigator
  • Version updates may incur migration costs

Use Cases

Web + mobile hybrid app (URL-based routing required) Apps with authentication flows