GoRouter class Get started Upgrading Configuration Navigation Redirection Web Deep linking Named routes 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.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
location String
Gets the current location.
no setter
routeConfiguration → RouteConfiguration
The route configuration. Used for testing.
no setter
routeInformationParser → GoRouteInformationParser
The route information parser used by GoRouter.
no setteroverride
routeInformationProvider → GoRouteInformationProvider
The route information provider used by GoRouter.
no setteroverride
routerDelegate → GoRouterDelegate
The router delegate. Provide this to the MaterialApp or CupertinoApp's .router() constructor
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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 nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
pop<T extends Object?>([T? result]) → void
Pop the top page off the GoRouter's page stack.
push<T extends Object?>(String location, {Object? extra}) Future<T?>
Push a URI location onto the page stack w/ optional query parameters and promise, e.g. /family/f2/person/p1?color=blue.
pushNamed<T extends Object?>(String name, {Map<String, String> params = const <String, String>{}, Map<String, dynamic> queryParams = const <String, dynamic>{}, Object? extra}) Future<T?>
Push a named route asynchronously onto the page stack w/ optional parameters and promise.
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<T extends Object?>(String location, {Object? extra}) Future<T?>
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<T extends Object?>(String name, {Map<String, String> params = const <String, String>{}, Map<String, dynamic> queryParams = const <String, dynamic>{}, Object? extra}) Future<T?>
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.