Skip to content

[go router] Allow building of a path not defined with routes and subroutes #107240

Description

@ronw98

Use case

I'm developing an application that has a page that can be accessed via multiple locations:
The page is DetailsPage and is accessible from HomePage and ListPage

For now to access it I need to define two routes: /home/details and /list/details

Which gives the following code

GoRoute(
  path: '/',
  // ...
  routes: [
    GoRoute(
      path: 'home',
      routes: [
        GoRoute(path:'details'),
      ]
    ),
    GoRoute(
      path: 'list',
      routes: [
        GoRoute(path:'details'),
      ]
    ),
  ]
)

It duplicates the route declaration and is not ideal at all. (It is ok when the route has only two access points but what if it has 10 or not event a pre determined number?)

Proposal

A solution to that would be to be able to declare some GoRoutes as accessible from multiple points.
Either allowing for something like

// Re usable subroute route
GoSubRoute(
  path: 'details',
  accessibleFrom: ['/home', '/list'],
)

Or even using wildcard or regexp

GoRoute(
  path: '*/details',
)

That last solution has the advantage of allowing the opening of any stack of pages from a deeplink (for example /home/list/details) without having to define all the possible routes as it is required today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions