RouteBase class abstract
The base class for GoRoute and ShellRoute.
Routes are defined in a tree such that parent routes must match the current location for their child route to be considered a match. For example the location "/home/user/12" matches with parent route "/home" and child route "user/:userId".
To create sub-routes for a route, provide them as a GoRoute list with the sub routes.
For example these routes:
/ => HomePage()
family/f1 => FamilyPage('f1')
person/p2 => PersonPage('f1', 'p2') ← showing this page, Back pops ↑
Can be represented as:
final GoRouter _router = GoRouter(
routes: <GoRoute>[
GoRoute(
path: '/',
pageBuilder: (BuildContext context, GoRouterState state) => MaterialPage<void>(
key: state.pageKey,
child: HomePage(families: Families.data),
),
routes: <GoRoute>[
GoRoute(
path: 'family/:fid',
pageBuilder: (BuildContext context, GoRouterState state) {
final Family family = Families.family(state.pathParameters['fid']!);
return MaterialPage<void>(
key: state.pageKey,
child: FamilyPage(family: family),
);
},
routes: <GoRoute>[
GoRoute(
path: 'person/:pid',
pageBuilder: (BuildContext context, GoRouterState state) {
final Family family = Families.family(state.pathParameters['fid']!);
final Person person = family.person(state.pathParameters['pid']!);
return MaterialPage<void>(
key: state.pageKey,
child: PersonPage(family: family, person: person),
);
},
),
],
),
],
),
],
);
If there are multiple routes that match the location, the first match is used. To make predefined routes to take precedence over dynamic routes eg. '/:id' consider adding the dynamic route at the end of the routes.
For example:
final GoRouter _router = GoRouter(
routes: <GoRoute>[
GoRoute(
path: '/',
redirect: (_, __) => '/family/${Families.data[0].id}',
),
GoRoute(
path: '/family',
pageBuilder: (BuildContext context, GoRouterState state) => ...,
),
GoRoute(
path: '/:username',
pageBuilder: (BuildContext context, GoRouterState state) => ...,
),
],
);
In the above example, if /family
route is matched, it will be used.
else /:username
route will be used.
See main.dart
- Mixed-in types
- Annotations
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
An optional key specifying which Navigator to display this route's screen
onto.
final
- redirect → GoRouterRedirect?
-
An optional redirect function for this route.
final
-
routes
→ List<
RouteBase> -
The list of child routes associated with this route.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringShort(
) → String -
A brief description of this object, usually just the runtimeType and the
hashCode.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
routesRecursively(
Iterable< RouteBase> routes) → Iterable<RouteBase> -
Builds a lists containing the provided routes along with all their
descendant
routes
.