GoRouter.dev

Current field guide · 2026

Your first route

Connect a URL to a screen, then prove that the same destination works after a reload.

Edition published 21 Oct 2026go_router 18.1.1 reference
On this page

Start with the URL contract

Write down the URLs your app needs before drawing a navigation stack. A useful first map is /, /books/:bookId, and /settings. Give durable resources a path parameter; put optional filters in the query string.

Install for your SDK

Run flutter pub add go_router in the application directory. Let Pub resolve a release compatible with your SDK. The package API reports go_router 18.1.1 with Dart ^3.12.0 and Flutter >=3.44.0 at this edition's publication. An older Flutter project may need an earlier compatible package version.

Connect the router

Create a stable router instance and pass it to MaterialApp.router(routerConfig: router). Recreating it during every widget build can discard the navigation state you meant to preserve. The starter below uses one top-level instance.

Check the real entry points

Open the home screen, navigate to a book, paste that book URL into a fresh browser tab, and refresh it. A working in-app button does not prove that your web host serves deep links correctly. Keep the downloaded starter as a small reference, then add your own screens incrementally.

dart / example
final router = GoRouter(
  routes: [
    GoRoute(path: '/', builder: (_, __) => const HomeScreen()),
    GoRoute(
      path: '/books/:bookId',
      builder: (_, state) => BookScreen(
        id: state.pathParameters['bookId']!,
      ),
    ),
  ],
);

MaterialApp.router(routerConfig: router);
Earlier edition: read the complete original guide. Its older APIs are kept in historical context.

Sources & version context

GoRouter.dev documentation edition. Examples illustrate the APIs described in the linked primary documentation. Adapt application-owned widgets and services to your project. They are not an executed Flutter session in this browser.

Read three versions before copying a routing example

A dependency constraint, the resolved package version and the installed SDK are different facts. The pub.dev metadata checked on 24 October 2026 lists go_router 18.1.1 with Dart ^3.12.0 and Flutter >=3.44.0. Reading that metadata does not demonstrate that an application builds.

  1. Read pubspec.yaml for the requested package constraint. A caret constraint such as ^18.1.1 describes an allowed range; it is not a record of the exact package used by every machine.
  2. Read pubspec.lock for the resolved go_router version, then compare it with the documentation version. In a hypothetical lockfile containing 18.1.0, do not label an 18.1.1 example as tested against that project without a separate compatibility check.
  3. Record the actual flutter --version output in the project’s own environment and compare the SDK requirements. Run the normal analyser, tests and build only where an authorised, existing SDK is available. If it is absent, preserve the candidate and state that execution is blocked.
Read three versions before copying a routing example — CONSTRAINT; LOCKFILE; SDK + DOCS
Read three versions before copying a routing example — CONSTRAINT; LOCKFILE; SDK + DOCS

Worked record

Requestedpubspec.yaml: go_router: ^18.1.1 — a constraint, not an execution result.
Resolvedpubspec.lock: inspect packages → go_router → version. Record the actual value rather than copying this illustrative value.
SDK requirementPublished 18.1.1 metadata: Dart ^3.12.0; Flutter >=3.44.0. The project’s actual SDK still needs checking.
Verification boundaryVerified 24 October 2026 with Flutter 3.47.8 / Dart 3.13.7 / go_router 18.1.1: analyze exit 0; four widget tests pass; release Web build exit 0. See the complete project and verification record below.
Handover recordConstraint __; lockfile version __; SDK output __; documentation version __; commands/results __; unresolved mismatch __.

The complete starter below has now passed real Flutter checks. The JavaScript Route Atlas remains a separate teaching model and is not the Dart test runner.

Primary sources: pub.dev: go_router metadata · go_router 18.1.1 documentation

A starter with an actual build record

Verified on 24 October 2026: Flutter 3.47.8, Dart 3.13.7 and go_router 18.1.1. The package version is pinned, the resolved dependencies are in pubspec.lock, and the download contains a complete Web host, Dart entry point and tests.

  1. Extract the source project into a working folder. Use the exact SDK above to reproduce this record; a newer or older SDK is a different verification environment.
  2. Run flutter pub get --enforce-lockfile, then the commands below. Keep the lockfile and read any dependency or SDK mismatch rather than silently upgrading.
  3. Read test/routing_test.dart alongside lib/main.dart. The routes are /, /books/:bookId with optional ?tab=notes, and /settings. An unknown route has a return-home action.
flutter analyze --no-pub
No issues found! / exit 0

flutter test --no-pub --reporter expanded
+4: All tests passed! / exit 0

flutter build web --release --csp --no-web-resources-cdn --no-wasm-dry-run
✓ Built build/web / exit 0

The tests cover a Home → book → Home journey, a direct book route with a default query value, settings push/pop, and unknown-route recovery. These are widget tests using the real Flutter test engine. They do not establish browser address-bar history, deep-link refresh on a particular server, or Android/iOS compatibility.

URL /books/42?tab=notes → route match → widget assertion → release output
URL input, route and query values, widget assertions, and the separate build result are distinct evidence.

Complete tested source project ↓

Compiled Web release archive ↓

Machine-readable verification record

The compiled archive is provided as a build artifact. No live Flutter demo is claimed here: CanvasKit requires a compatible WebAssembly policy, and the documentation site’s existing CSP has not been weakened. The source README explains the local HTTP-host boundary. No separate Chrome process was used for these checks.

Find your next route