Replies: 42 comments 9 replies
|
This is what currently stops me from moving to V6. Moving the validation logic to components is not suitable IMOH, and waste resources. I would suggest that instead of providing arbitrary regex in each path, we define some formats in the config level, then use them within paths. This also could be the only way to use regex within paths. For example, {
"uuid": /([0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/,
"drinks": /(wines|whiskeys|sakes|beers)/
}Then use them within paths: <Route path="{drinks}/:id{uuid}" element={<Teams />}>
// or
<Route path="{drinks}/id:uuid" element={<Teams />}>
// or
<Route path="{drinks}/{uuid:id}" element={<Teams />}>Or as a separate validation prop: <Route path="{drinks}/:id" validate={{ id: 'uuid' }} element={<Teams />}> |
|
I was also about to open a feature request for a similar case. In my codebase, I heavily rely on I was thinking if we can have a plugin-like solution where we can supply a |
|
While an API for 3rd party path parsing sounds cool, I think this functionality is pretty basic and popular. Unsure why it was removed. At the top of my switch, I have <Switch>
<Route path='/:membershipType([1|2|3|4|5])/:membershipId([0-9]+)/:characterId([0-9]+)?' component={ProfileRoutes} />
...Am I now supposed to write a route for /1-5/? |
|
https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API |
|
I agree with all of the above. The pattern matching was handled nicely with v5, why remove such a critical feature? |
|
+1 for getting this functionality added back in. Just like optional routing parameters, this was such a useful (and critical feature), and it's not clear why this functionality was removed...we're gonna have to stay on v5 because of it. I'd love to hear a reasoning from the package maintainers as to what led to this surprising and large change. |
|
They justified the removal in the changelog/upgrade docs. The main reason
is size, `path-to-regexp` is big. I also believe it has to do a bit with
`Remix` as they are using file-system-based routing, just like Next and
folder/filenames don't support most of the regexp syntax characters. Yet I
don't see any reason not to provide an API to be able to extend. Some
response from the team would be nice regarding this topic, at least to know
if they consider this. Not having this will keep me on v5 forever for sure.
…On Mon, Dec 6, 2021 at 9:46 PM queengooborg ***@***.***> wrote:
+1 for getting this functionality added back in. Just like optional
routing parameters, this was such a useful (and critical feature), and it's
not clear why this functionality was removed...we're gonna have to stay on
v5 because of it. I'd love to hear a reasoning from the package maintainers
as to what led to this surprising and large change.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#8254 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHLJQFB3WWYCG2ECRLUN4TUPUOKTANCNFSM5HP3PYKQ>
.
|
|
Likewise. In my opinion, it's a big step backwards. Removing (presumably) widely-used functionality with the terse note only to "remove it and simplify your route paths" is upsetting. It's a massive breaking change. Reducing file size is great, but this feels like an over-optimization at the expense of better functionality and backwards compatibility. |
|
A lot of useful feature has been removed from v6. I think overly obsessive with the package size is really weighting on the usefulness of the library. What if the majority of user has to workaround those feature anyway, or just simply refuse to upgrade to v6? |
|
The maintainers aren't responding to the concerns. As others mentioned, we are looking into https://github.com/molefrog/wouter as we doubt that v5 will be maintained, and we can't use the reduced feature v6. |
|
Nice, the matcher prop does exactly what we wish for here and it has a
react-router compatible API. Thanks for sharing.
…On Mon, Dec 13, 2021, 16:44 bluepeter ***@***.***> wrote:
The maintainers aren't responding to the concerns. As others mentioned, we
are looking into https://github.com/molefrog/wouter as we doubt that v5
will be maintained, and we can't use the reduced feature v6.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#8254 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHLJQAHDRXPZ2RDLHFUM33UQYIGDANCNFSM5HP3PYKQ>
.
|
|
what is the solution at the moment? I got |
|
@kulakowka, however , it works after changing it to |
|
Wish I'd known this had been removed before starting a migration from 5 to 6. The migration docs did not make it clear this would be a breaking change, it's buried half way down the page as a side note. |
|
@VeXell If you need to do param validation, I would do that in a |
|
I'm going to convert this to a discussion so it can go through our new Open Development process. Please upvote the new Proposal if you'd like to see this considered! |
|
@brophdawg11 yes, might be it be helpful, but i did not find any examples how |
|
How can I set Router's formatsConfig, I did not find it in react router v6? |
|
I'm not sure if this is of value to anyone, but I thought of an exciting way to tackle this, avoiding needing to type out each route. To accomplish this, use a layout element "guard" to enforce the specific parameters you want to enforce. If they are valid, then render the outlet for the nested route; otherwise, Navigate or render a fallback. It would look like the following: I tried this in an example when attempting to recreate how Google Calendar handles routing for the views and dates. It's messy, but it can at least illustrate the concept. One thing to note on this is that Stackblitz's route information doesn't update properly so if you'd like to mess around with the routes, you'll need to manually type them in. You can see my repo here: https://stackblitz.com/edit/vitejs-vite-nxtuof?file=package.json,src%2FApp.tsx&terminal=dev The neat part about this one is that I leveraged |
|
If the goal is to not rely on Something like |
|
In the v6 migration guide It says:
Is that bit about adding "some advanced param validation at some point" still relevant? I have to agree that this feels like a step backwards without even a very basic replacement. Having to do param validation in the component feels like it is mixing routing and component logic. |
|
What's the likelihood of adding support for this feature any time soon? |
|
Guys, sorry, but you can't be serious. There’s no way this isn’t a bad joke. How many upvotes do you need? This is an essential feature for any router. I ran into this issue with SEO-friendly URLs like Of course, this is open source, and everyone can contribute, but it seems like the maintainers don’t want this feature to become a reality in any way. |
|
link this proposal please, it's resolves the same problem |
|
I come here to request getting this feature back. In our 20 years old products, we have to support some legacy paths for those old clients. In v5 we simply do `path: "oldPath|newPath". Very clean and readable. |
|
Perhaps I'm really not suitable for using react. |
|
Had ternaries in the route definitions in v5 so our If you're okay with them, it's quite easy: const { pathname } = useLocation()
const isIndexPath = pathname?.match(/^\/index\.[a-zA-Z]+$/i) // or whatever RegExp you require
return (
<Routes>
{isIndexPath ? <Route path={pathname} element={<Navigate to='/' replace />} /> : null}and then there's no need to wait for any other feature. |
|
I've been working on a branch that uses a minimal, opt-in “pluggable matcher” design that keeps current behavior by default. The core is a RouteMatcher interface with matchPath + matchRoutes, and a setRouteMatcher() API to swap in a custom implementation. The default matcher just wraps the existing logic so there are (should be?) zero breaking changes. This would let teams plug in alternate matchers (e.g. regex/named captures or a Hono-style router) without touching React Router’s internals, while leaving existing users unaffected. I’ve got a branch with the interface, default matcher, integration points, and tests if you want to look at concrete changes. It doesn't work yet because I haven't figured out how to get the types to work with Vite, but in theory it should work. Something like this: +// lib/router/matcher.ts
+export interface RouteMatcher {
+ readonly name: string;
+ matchPath(pattern, pathname): PathMatch | null;
+ matchRoutes(routes, location, basename?): RouteMatch[] | null;
+}
// lib/router/utils.ts
+let customMatcher: RouteMatcher | null = null;
+export function setRouteMatcher(m: RouteMatcher | null) { customMatcher = m; }
export function matchPath(pattern, pathname) {
+ if (customMatcher) return customMatcher.matchPath(pattern, pathname);
// existing logic...
}
export function matchRoutes(routes, location, basename = "/") {
+ if (customMatcher) return customMatcher.matchRoutes(routes, location, basename);
// existing logic...
}https://github.com/dangayle/react-router/tree/feat/pluggable-matcher |
|
👋 I've got a PR open with a POC of incorporating let router = createBrowserRouter(
[
{
path: "/:food/:drink",
unstable_validateParams: {
food: /^(meats|cheeses)$/,
drink: /^(beers|sakes)$/,
},
},
],
{
future: {
unstable_routePatternMatching: true,
},
},
);I deployed these changes in an experimental |
Uh oh!
There was an error while loading. Please reload this page.
What is the new or updated feature that you are suggesting?
update current route.path to allow more conditional regex paths for multiple conditions like in v5.
v5 route:
/(wines|whiskeys|sakes|beers)/:id/:productName?Why should this feature be included?
current v6 doesnt include this anymore. only allow strict routes.
All reactions