Skip to content

[go_router] relax requirement for child route paths preventing child routes from starting with '/' #145867

@cedvdb

Description

@cedvdb

Steps to reproduce

Create a GoRoute starting with '/'. That compiles just fine. Now place that route as a child of another route => assertion error.

Expected results

Either all routes should require / or none should. As it is currently, it violates an OOP principles where an object must be in a valid state after construction.

Concretely I cannot create an AccountRoute for example that is not aware where it is going to be placed. Will it be a child of another route or will it be a "root" route ? None of its business. You also can't move route around without modifying their path.

If internally go_router requires some special rules it should deal with it internally and not reflected those in the public API.

Actual results

assertion throws: sub-route path may not start or end with "/": $route'

Code sample

GoRouter(
  routes: [
       GoRoute(
          path:  '/a',
          builder: (context, state) => Text(''),
        routes: [
          GoRoute(
            path:  '/b',
            builder: (context, state) => Text(''),
            ),
         ]
       ),
  ]
);

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.19.2, on Microsoft Windows [Version 10.0.22631.3296], locale en-BE)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.32)
[√] Android Studio (version 2023.1)
[√] VS Code (version 1.87.2)
[√] Connected device (3 available)
[√] Network resources

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectfound in release: 3.19Found to occur in 3.19found in release: 3.21Found to occur in 3.21has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: 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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions