Historical source · 2021–2022
Original guide · Examples
Preserved original documentation, with its original version context.
On this page
Historical text from the original project repository (2021–2022). For the current APIs, use the 2026 field guide. Original wording and credits are preserved.
Examples
You can see go_router in action via the following examples:
main.dart: define a basic routing policy using a set of declarativeGoRouteobjectserror_screen.dart: define a custom error screen for use when there's a routing or builder errorinit_loc.dart: start at a specific location instead of home (/), which is the defaultsub_routes.dart: provide a stack of pages based on a set of sub routespush.dart: provide a stack of pages based on a series of calls tocontext.push()redirection.dart: redirect one route to another based on changing app statequery_params.dart: optional query parameters will be passed to all buildersrouter_stream_refresh.dart: use aStreamto trigger a refresh instead of aListenableloading_page.dart: load a repository once the user has logged in, showing a loading screen while they waitnamed_routes.dart: navigate via name instead of location URItransitions.dart: use custom transitions during routingasync_data.dart: async data lookupnested_nav.dart: include information about children on a page as part of the route locationnav_builder.dart: inject widgets above theNavigatorwidgetshared_scaffold.dart: show anavBuilderimplementation that shares a scaffold between pagesurl_strategy.dart: turn off the # in the Flutter web URLuser_input.dart: usingNavigatoror a go_router route to navigate to a page that gathers user input as well as canceling a pop when the user presses the Back buttonnav_observer.dart: pass additional information to theNavigatorObservervia default args toMaterialPage, etc.state_restoration.dart: test to ensure that go_router works with state restoration (it does)cupertino.dart: test to ensure that go_router works with the Cupertino design language as well as Material (it does)widgets_app.dart: test to ensure that go_router works with the WidgetsApp as well as theMaterialApp(it does)router_neglect.dart: prevent the browser from creating history entries when navigatingbooks/main.dart: port of the navigation_and_routing sample to use go_router
You can run these examples from within your IDE of choice or from the example folder via the command line:
sh / example
$ cd example
$ flutter run lib/main.dartSources & 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.