GoRouter.dev

Historical source · 2021–2022

Migrating to 2.0

The original migration guide, preserved with a route to current upgrade instructions.

Edition published 21 Oct 2026Original APIs
On this page
This migration belongs to the early package history. It is preserved for projects that still need that transition. For a current application, consult the current upstream upgrading documentation before changing dependencies.

Migrating to 2.0

By popular demand, there is a breaking change in the go_router 2.0 release: the params property of the GoRouterState object has been split into two properties:

  • params for parameters that are part of the path and, e.g. /family/:fid
  • queryParams for parameters that added optionally at the end of the location, e.g. /login?from=/family/f2

In the 1.x releases, the params property was a single object that contained both the path and query parameters in a single map. For example, if you had been using the params property to access query parameters like this in 1.x:

dart / example
GoRoute(
  path: '/login',
  pageBuilder: (context, state) => MaterialPage<void>(
    key: state.pageKey,
    // 1.x: accessing query parameters
    child: LoginScreen(from: state.params['from']),
  ),
),

in 2.0, you would access the query parameters like this:

dart / example
GoRoute(
  path: '/login',
  pageBuilder: (context, state) => MaterialPage<void>(
    key: state.pageKey,
    // 2.0: accessing query parameters
    child: LoginScreen(from: state.queryParams['from']),
  ),
),

Likewise, if you were using named routes in 1.x, you may have been passing both path and query parameters like so:

dart / example
ListTile(
  title: Text(p.name),
  // 1.x: passing both path and query parameters
  onTap: () => context.goNamed(
    'person',
    // anything not a path param was assumed to be a query param
    {'fid': family.id, 'pid': p.id, 'qid': 'quid'},
  ),
),

Now you'll need to change your code to do the following in 2.0:

dart / example
ListTile(
  title: Text(p.name),
  // 2.0: passing both path and query parameters
  onTap: () => context.goNamed(
    'person',
    params: {'fid': family.id, 'pid': p.id},
    queryParams: {'qid': 'quid'},
  ),
),

I got a little clever merging the two kinds of parameters into a single scope and hopefully this change makes things a little more clear.

Sources & version context

GoRouter.dev documentation edition. The preserved text describes the original package APIs. Follow the current guide before using it in a new project.

Find your next route