Skip to content

[go_router] Relax subroute path requirements (allow root and child routes to have the same path forms ) - #7647

Merged
auto-submit[bot] merged 11 commits into
flutter:mainfrom
cedvdb:remove_unnecessary_path_requirements
Oct 3, 2024
Merged

auto-submit[bot] merged 11 commits into
flutter:mainfrom
cedvdb:remove_unnecessary_path_requirements

Conversation

@cedvdb

@cedvdb cedvdb commented Sep 13, 2024 •

Copy link
Copy Markdown
Contributor

Before this change GoRoute constructor allowed Schroedinger routes which were neither in a valid state nor an invalid state until they were used. EG: GoRoute(path: '/some-route') was valid as a top route but invalid as a child route. This prevents routes from being moved around and prevents building upon go router.

To solve this I see two solution:

  1. Breaking change: Require all routes to start with / (or none)
  2. Non breaking: Allow all routes to start or not with /

Since I did not want to introduce a breaking change I followed option 2, which allows all routes to be of the form /some-route or some-route. However, breaking changes aside, I believe it would be better to use solution 1 as it's more predictible.

@chunhtai What do you think about those options ?

Related issue: Fix flutter/flutter#145867

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@cedvdb
cedvdb requested a review from chunhtai as a code owner September 13, 2024 21:18
@google-cla

google-cla Bot commented Sep 13, 2024

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@cedvdb cedvdb changed the title [go_router] Remove unnecessary path requirements [draft] [go_router] Remove unnecessary path requirements Sep 13, 2024
Comment thread packages/go_router/lib/src/route.dart Outdated

@cedvdb cedvdb Sep 15, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can't predict whether or not loc starts with / or not as it is user defined. We could make it so the GoRoute constructor requires all routes to start with / but that would be a breaking change

@cedvdb cedvdb changed the title [draft] [go_router] Remove unnecessary path requirements [go_router] Remove unnecessary path requirements Sep 15, 2024
@cedvdb cedvdb changed the title [go_router] Remove unnecessary path requirements [go_router] Relax subroute path requirements (no leading "/" ) Sep 15, 2024
@cedvdb cedvdb changed the title [go_router] Relax subroute path requirements (no leading "/" ) [go_router] Relax subroute path requirements (allow root and child routes to have the same path forms ) Sep 15, 2024
@cedvdb cedvdb changed the title [go_router] Relax subroute path requirements (allow root and child routes to have the same path forms ) [draft][go_router] Relax subroute path requirements (allow root and child routes to have the same path forms ) Sep 15, 2024
@cedvdb cedvdb changed the title [draft][go_router] Relax subroute path requirements (allow root and child routes to have the same path forms ) [go_router] Relax subroute path requirements (allow root and child routes to have the same path forms ) Sep 16, 2024

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread packages/go_router/test/go_router_test.dart Outdated
Comment thread packages/go_router/CHANGELOG.md Outdated
@chunhtai
chunhtai requested a review from hannah-hyj September 18, 2024 21:53
@cedvdb

cedvdb commented Oct 1, 2024

Copy link
Copy Markdown
Contributor Author

@Hangyujin requesting the additional necessary review

@hannah-hyj hannah-hyj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for your contribution!

@hannah-hyj

Copy link
Copy Markdown
Member

Can you update the PR to resolve the conflicts

@cedvdb

cedvdb commented Oct 3, 2024 •

Copy link
Copy Markdown
Contributor Author

@Hangyujin done, not sure why all previous commits were readded 9 minutes ago, I only rebased since your approval (and added a typo fix for my change in changelog).

@chunhtai chunhtai added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 3, 2024
@auto-submit
auto-submit Bot merged commit 6058294 into flutter:main Oct 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 4, 2024
auto-submit Bot pushed a commit to flutter/flutter that referenced this pull request Oct 4, 2024
flutter/packages@429650f...05bf1d4

2024-10-04 [email protected] [various] Update Swift plugins for non-nullable generics (flutter/packages#7742)
2024-10-04 [email protected] [url_launcher] Update Android Pigeon (flutter/packages#7744)
2024-10-04 [email protected] [xdg_directories] Add `stateHome` property (flutter/packages#7766)
2024-10-03 [email protected] [file_selector] Update Android Pigeon for non-nullable generics (flutter/packages#7781)
2024-10-03 [email protected] [go_router] Relax subroute path requirements (allow root and child routes to have the same path forms ) (flutter/packages#7647)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…utes to have the same path forms ) (flutter#7647)

Before this change `GoRoute` constructor allowed Schroedinger routes which were neither in a valid state nor an invalid state until they were used. EG: `GoRoute(path: '/some-route')`  was valid as a top route but invalid as a child route. This prevents routes from being moved around and prevents building upon go router. 

To solve this I see two solution:

  1. Breaking change: Require all routes to start with `/` (or none)
  2. Non breaking: Allow all routes to start or not with `/`

Since I did not want to introduce a breaking change I followed option 2, which allows all routes to be of the form `/some-route` or `some-route`. However, breaking changes aside, I believe it would be better to use solution 1 as it's more predictible.

@chunhtai What do you think about those options ? 

Related issue: Fix flutter/flutter#145867
bisor0627 pushed a commit to bisor0627/packages that referenced this pull request Jun 19, 2026
…utes to have the same path forms ) (flutter#7647)

Before this change `GoRoute` constructor allowed Schroedinger routes which were neither in a valid state nor an invalid state until they were used. EG: `GoRoute(path: '/some-route')`  was valid as a top route but invalid as a child route. This prevents routes from being moved around and prevents building upon go router. 

To solve this I see two solution:

  1. Breaking change: Require all routes to start with `/` (or none)
  2. Non breaking: Allow all routes to start or not with `/`

Since I did not want to introduce a breaking change I followed option 2, which allows all routes to be of the form `/some-route` or `some-route`. However, breaking changes aside, I believe it would be better to use solution 1 as it's more predictible.

@chunhtai What do you think about those options ? 

Related issue: Fix flutter/flutter#145867
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: go_router

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants