Skip to content

[go_router] ShellRoute should have a redirect method similar to GoRoute #114559

@ahmednfwela

Description

@ahmednfwela

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:

  1. repeat the redirect logic for each sub route of a shell route
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions