GoRouter class Null safety Get started Upgrading Configuration Navigation Redirection Web Deep linking Named routes Logging Error handling

The route configuration for the app.

The routes list specifies the top-level routes for the app. It must not be empty and must contain an GoRouter to match /.

See the Get started example, which shows an app with a simple route configuration.

The redirect callback allows the app to redirect to a new location. Alternatively, you can specify a redirect for an individual route using GoRoute.redirect. If BuildContext.dependOnInheritedWidgetOfExactType is used during the redirection (which is how of methods are usually implemented), a re-evaluation will be triggered when the InheritedWidget changes.

See also:

  • Configuration
  • GoRoute, which provides APIs to define the routing table.
  • examples, which contains examples for different routing scenarios.
Inheritance
Implemented types

Constructors

GoRouter({required List<RouteBase> routes, GoRouterPageBuilder? errorPageBuilder, GoRouterWidgetBuilder? errorBuilder, GoRouterRedirect? redirect, Listenable? refreshListenable, int redirectLimit = 5, bool routerNeglect = false, String? initialLocation, List<NavigatorObserver>? observers, bool debugLogDiagnostics = false, GlobalKey<NavigatorState>? navigatorKey, String? restorationScopeId})
Default constructor to configure a GoRouter with a routes builder and an error page builder.

Properties

backButtonDispatcher BackButtonDispatcher
The BackButtonDispatcher that is used to configure the Router.
final
hashCode int
The hash code for this object.
read-only, inherited
hasListeners bool
Whether any listeners are currently registered.
@protected, read-only, inherited
location String
Gets the current location.
read-only
routeConfiguration → RouteConfiguration
The route configuration. Used for testing.
@visibleForTesting, read-only
routeInformationParser → GoRouteInformationParser
The route information parser used by GoRouter.
read-only, override
routeInformationProvider → GoRouteInformationProvider
The route information provider used by GoRouter.
read-only, override
routerDelegate → GoRouterDelegate
The router delegate. Provide this to the MaterialApp or CupertinoApp's .router() constructor
read-only, override
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
canPop() bool
Returns true if there is more than 1 page on the stack.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
go(String location, {Object? extra}) → void
Navigate to a URI location w/ optional query parameters, e.g. /family/f2/person/p1?color=blue
goNamed(String name, {Map<String, String> params = const <String, String>{}, Map<String, dynamic> queryParams = const <String, dynamic>{}, Object? extra}) → void
Navigate to a named route w/ optional parameters, e.g. name='person', params={'fid': 'f2', 'pid': 'p1'} Navigate to the named route.
namedLocation(String name, {Map<String, String> params = const <String, String>{}, Map<String, dynamic> queryParams = const <String, dynamic>{}}) String
Get a location from route name and parameters. This is useful for redirecting to a named location.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
pop() → void
Pop the top page off the GoRouter's page stack.
push(String location, {Object? extra}) → void
Push a URI location onto the page stack w/ optional query parameters, e.g. /family/f2/person/p1?color=blue
pushNamed(String name, {Map<String, String> params = const <String, String>{}, Map<String, dynamic> queryParams = const <String, dynamic>{}, Object? extra}) → void
Push a named route onto the page stack w/ optional parameters, e.g. name='person', params={'fid': 'f2', 'pid': 'p1'}
refresh() → void
Refresh the route.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
replace(String location, {Object? extra}) → void
Replaces the top-most page of the page stack with the given URL location w/ optional query parameters, e.g. /family/f2/person/p1?color=blue.
replaceNamed(String name, {Map<String, String> params = const <String, String>{}, Map<String, dynamic> queryParams = const <String, dynamic>{}, Object? extra}) → void
Replaces the top-most page of the page stack with the named route w/ optional parameters, e.g. name='person', params={'fid': 'f2', 'pid': 'p1'}.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

of(BuildContext context) GoRouter
Find the current GoRouter in the widget tree.