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

Support optional static segments and splats in href() util #13168

Closed
wants to merge 4 commits into from

Conversation

vjee
Copy link

@vjee vjee commented Mar 6, 2025

Fixes #13055
Fixes #13166

This PR adds support for optional static segments and splats to the href() util.

Optional static segments

For optional static segments, true can be passed as param value to enable the segment. Not providing the param, or passing a falsy value ignores the segment.

href("/users/:userId/edit?", { userId: "abc123" }) // "/users/abc123"
href("/users/:userId/edit?", { userId: "abc123", edit: true }) // "/users/abc123/edit"

Splats

A splat value can be provided with a "*" param.

href("/a/*", { "*": "hello" }) // "/a/hello"
href("/a/*", { "*": "hello/world" }) // "/a/hello/world"

Copy link

changeset-bot bot commented Mar 6, 2025

🦋 Changeset detected

Latest commit: 37996f2

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

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Major
react-router Major
@react-router/fs-routes Major
@react-router/remix-routes-option-adapter Major
@react-router/architect Major
@react-router/cloudflare Major
react-router-dom Major
@react-router/express Major
@react-router/node Major
@react-router/serve Major
create-react-router Major

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 Mar 6, 2025

Hi @vjee,

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 [email protected].

Thanks!

- The Remix team

@vjee vjee force-pushed the href-optional-segments-and-splats branch from be5dae1 to 737c6cb Compare March 6, 2025 09:05
@vjee vjee changed the base branch from main to dev March 6, 2025 09:05
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Mar 6, 2025

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

@vjee vjee force-pushed the href-optional-segments-and-splats branch 3 times, most recently from a8fe21f to e5f3957 Compare March 6, 2025 10:38
@vjee vjee force-pushed the href-optional-segments-and-splats branch from e5f3957 to 0db10b5 Compare March 6, 2025 10:39
@vjee
Copy link
Author

vjee commented Mar 9, 2025

I didn't realize the Register['params'] type was also used for loaders etc, so changing the shape of it for the href util is not a viable solution.
Therefore I closed this PR.

@vjee vjee closed this Mar 9, 2025
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.

href() builder produces invalid URL on optional segments
1 participant