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

feat: optional params and static segments #9650

Merged
merged 6 commits into from
Nov 30, 2022

Conversation

lordofthecactus
Copy link
Contributor

@lordofthecactus lordofthecactus commented Nov 29, 2022

Closes: #9550

Allows optional params and optional static segments

Optional params examples

:lang?/about will get expanded matched with

/:lang/about
/about

/multistep/:widget1?/widget2?/widget3?
Will get expanded matched with:

/multistep
/multistep/:widget1
/multistep/:widget1/:widget2
/multistep/:widget1/:widget2/:widget3

Same with static segments

/fr?/about will get expanded and matched with:

/about
/fr/about

Context

Code was added at the point of flattenRoutes

Feedback required

Should we allow intercalated situations? currently:
/one/:two?/three/four? gets matched with:

/one/:two/three
/one/:two/three/:four

@changeset-bot
Copy link

changeset-bot bot commented Nov 29, 2022

🦋 Changeset detected

Latest commit: afbcf9a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
react-router Minor
@remix-run/router Minor
react-router-dom Minor
react-router-dom-v5-compat Minor
react-router-native Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 29, 2022

Hi @lordofthecactus,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 29, 2022

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@ryanflorence
Copy link
Member

Awesome! Thanks Daniel! Pedro will work with you to get this over the finish line.

@ryanflorence
Copy link
Member

ryanflorence commented Nov 29, 2022

I think we should support /one/:two?/three/four?, yes. The concern is always ranking when multiple patterns match the URL. I imagine we handle it the same as if the user typed them all out by hand:

<Route path="/one/:two?/three/four?" />
// becomes
1. <Route path="/one/:two/three/four" />
2. <Route path="/one/three/four" />
3. <Route path="/one/:two/three" />
4. <Route path="/one/three" />

And the ranking should behave the same way.

@brophdawg11
Copy link
Contributor

Agreed - this "exploding" approach (before scoring/ranking) is designed to do just that - behave as if the user manually exploded the enumerations out on their own 👍

@pcattori
Copy link
Contributor

Looks like CI is failing due to filesize limitations. @lordofthecactus , could you bump the 35kB to 35.5kB for packages/router/dist/router.umd.min.js in package.json?

@lordofthecactus
Copy link
Contributor Author

@pcattori made the changes

@ryanflorence
Copy link
Member

We gotta get @developit in here to shrink it all down again.

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.

5 participants