Skip to content

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

Closed

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.

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    packageflutter/packages repository. See also p: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Jul 8, 2022
  2. added
    P3Issues that are less important to the Flutter project
    on Jul 12, 2022
  3. kwado-tech commented on Aug 14, 2023

    @kwado-tech

    @chunhtai, please, any updates on this as this elaborates a very practical usecase.

  4. chunhtai commented on Aug 14, 2023

    @chunhtai
    Contributor

    you can already do this with

    GoRoute(
      path: ':prefix/details',
    )
  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 14, 2023
  6. kwado-tech commented on Aug 15, 2023

    @kwado-tech

    @chunhtai Thanks. Can you point me to some expressive documentation/resource on this to grasp a proper usecase.

  7. chunhtai commented on Aug 15, 2023

    @chunhtai
    Contributor

    Closing this bug

  8. ASISBusiness commented on Aug 15, 2023

    @ASISBusiness

    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.

  9. github-actions commented on Aug 29, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions