Skip to content

Conversation

@nwleedev
Copy link

Problem

Optional dynamic segments (:param?) incorrectly match paths that extend the base path without a separator. For example:

matchPath('/test_route/:part?', '/test_route_more')
// Expected: null
// Actual: { params: { part: '_more' } }

The current regex pattern /?([^\/]+)? makes the slash and capture group independently optional.
It allows /test_route_more to match as /test_route + _more without a preceding slash.

Changes

The regex pattern to match paths

  • Groups the slash with the capture
  • Ensures slash and parameter appear together or not at all
  • Uses * instead of + to allow empty captures for backward compatibility
    (e.g., /sitemap/:lang?.xml matching /sitemap/.xml)

Impact

  • No breaking changes
    • Only fixes incorrect matching behavior
  • Maintains backward compatibility with existing patterns

Fixes #14640

@changeset-bot
Copy link

changeset-bot bot commented Dec 27, 2025

🦋 Changeset detected

Latest commit: 080bdac

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 Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch

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 Dec 27, 2025

Hi @nwleedev,

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Dec 27, 2025

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

@brophdawg11
Copy link
Contributor

Would you mind adding a changeset via pnpm changeset?

@nwleedev
Copy link
Author

nwleedev commented Jan 5, 2026

Would you mind adding a changeset via pnpm changeset?

Apologies for missing the changeset request. I have created a patch changeset for react-router.

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.

2 participants