redirect property
An optional redirect function for this route.
In the case that you like to make a redirection decision for a specific route (or sub-route), consider doing so by passing a redirect function to the GoRoute constructor.
For example:
final GoRouter _router = GoRouter(
routes: <GoRoute>[
GoRoute(
path: '/',
redirect: (_) => '/family/${Families.data[0].id}',
),
GoRoute(
path: '/family/:fid',
pageBuilder: (BuildContext context, GoRouterState state) => ...,
),
],
);
Redirect can also be used for conditionally preventing users from visiting routes, also known as route guards. One canonical example is user authentication. See Redirection for a complete runnable example.
Implementation
final GoRouterRedirect? redirect;