Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

cedvdb
Copy link
Contributor

@cedvdb cedvdb commented Sep 13, 2024

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.

Copy link

google-cla bot commented Sep 13, 2024

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 force-pushed the remove_unnecessary_path_requirements branch from 20a16d8 to 0b1eef0 Compare September 13, 2024 21:50
@cedvdb cedvdb changed the title [go_router] Remove unnecessary path requirements [draft] [go_router] Remove unnecessary path requirements Sep 13, 2024
loc = '/$loc';
}
return _pathRE.matchAsPrefix('/$loc') as RegExpMatch? ??
_pathRE.matchAsPrefix(loc) as RegExpMatch?;
Copy link
Contributor Author

@cedvdb cedvdb Sep 15, 2024

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
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -5502,6 +5473,94 @@ void main() {
),
);
});

testWidgets('should allow route paths without leading /',
Copy link
Contributor

Choose a reason for hiding this comment

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

not entirely sure about this test, wasn't this already allowed?

Copy link
Contributor Author

@cedvdb cedvdb Sep 18, 2024

Choose a reason for hiding this comment

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

Indeed. I felt it is more descriptive to add both next to each other even if somewhat unnecessary

packages/go_router/CHANGELOG.md Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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 '/'
2 participants