-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
Description
It is a common use case that a developer would want to guard an entire area in the app wrapped with ShellRoute
e.g. dashboard area
ShellRoute(
redirect: (context, state) {
//guard for authenticated users
},
builder: (context, state, child) => DashboardShellView(child: child),
routes: [
//sub routes
GoRoute(path: '/orders'),
GoRoute(path: '/dashboard'),
GoRoute(path: '/short_route'),
],
),there are 2 workarounds for this:
- repeat the redirect logic for each sub route of a shell route
- Group all guarded routes to be put under a single
GoRoute
e.g.:
ShellRoute(
builder: (context, state, child) => DashboardShellView(child: child),
routes: [
//sub routes
GoRoute(
path:'/dashboard',
redirect: (context, state) {
//guard for authenticated users
},
routes: [
GoRoute(path: 'orders'),
GoRoute(path: 'short_route'),
],
),
],
),however this has the downside of /short_route getting changed to /dashboard/short_route, and /orders getting changed to /dashboard/orders which might not be desirable
marko, harkairt, u382514, 0ttik, NikitaVasin and 18 morearthurbcd
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version