react-router
react-router copied to clipboard
feat: allow overriding matchPath function on Routes
This change allows users to override the base matchPath
used by the Routes
component. This will allow people to progressively migrate from the removal of validators and regex on paths that used to exist before v6.
This is a simple example of an implementation of a customMatchPath
function which could be further developed to use path-to-regexp
or other library for path matching.
const customMatchPath = (pattern: PathPattern | string, pathname: string) => {
if (pathname.length > 4) return matchPath(pattern, pathname);
return null;
};
<BrowserRouter>
<Routes
customMatchPath={customMatchPath}
>
<Route path="/:slug" element={<>Hello</>} />
</Routes>
</BrowserRouter>
https://github.com/remix-run/react-router/discussions/11546
⚠️ No Changeset found
Latest commit: bbec356264b5ac7e75092b8316064c33bcf3022e
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Hi @modi98,
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
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳
Is it required to have all the bundles stay within the 5% range of current file size? I see it's failing because of a small bump on bundle size, which I'm not even sure could be removed.
I'm assuming the bundle size increades a few bytes through the added imports of ParamParseKey
, PathMatch
, and PathPattern
.
Thank you for the POC implementation! I'm going to close this out as it's not yet been accepted as a proposed feature - but we'll have the link to this closed PR in the Proposal if it ends up being accepted and we want to re-open. In the meantime, you can always use patch-package
to add some of your own overrides.