GoRouter.dev

Current field guide · 2026

Load a resource after matching its URL

Use the URL to identify data, then give loading, missing, error, and ready states explicit UI.

Edition published 21 Oct 2026go_router 18.1.1 reference
On this page

Matching /books/42 proves that the URI fits a route template. It does not prove that book 42 exists, that the network is available, or that the current account may read it.

Keep the request lifecycle stable

Resolve the identifier at the screen boundary. Use your normal state-management or repository layer to load it, and avoid creating a new request on every widget rebuild. When the identifier changes, cancel or disregard an obsolete request so late results do not overwrite a newer screen.

Design four outcomes

Show a loading state, a useful missing-resource state, a recoverable error, and the loaded content. Authentication and authorization failures need deliberate handling rather than a generic empty page.

A route should be able to reconstruct the screen from its URI. Passing a previously loaded object through extra can be an optimization, but it should not be the only way to display a resource after a fresh entry or reload.

dart / example
GoRoute(
  path: '/books/:bookId',
  builder: (_, state) => BookScreen(
    id: state.pathParameters['bookId']!,
  ),
);
// BookScreen owns loading/error/missing/ready states.
// Its repository fetches data using the validated ID.
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.

Find your next route