[v6] URL param validation in <Route /> pathname #8125
Replies: 3 comments 1 reply
-
Same thoughts. I'm really don't like the new way to validate params. function App() {
return (
<Routes>
<Route path="en" element={<Lang code="en" />} />
<Route path="es" element={<Lang code="en" />} />
<Route path="fr" element={<Lang code="en" />} />
</Routes>
);
} When it could be ...
<Route path=":lang(en|es|fr)" element={<Lang />} />
...
function Lang() {
const { lang } = useParams();
...
} |
Beta Was this translation helpful? Give feedback.
-
I think it'd be great if there was some way to override the path mechanism so that people could reimplement the use of At the very least something that let's us validate/invalidate url params according to custom logic will be geart, and will also "bring back" optional params in a way. Building on the previous examples: <Route
path=":lang"
validateParams={params => /en|es|fr/.test(params.lang)}
element={<Lang />}
/> |
Beta Was this translation helpful? Give feedback.
-
validateParams implemented here. #11172 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I see the migration docs state...
And wanted to increase its priority popularity some how!
Due to the structure of my app, it's one of the few things preventing me from hopping on the v6 bandwagon. I understand it's still in beta and there's still a lot to do before we should expect to be able to use it in production but I'm worried it'll fall the wayside so I wanted to make note of it.
As far as the implementation goes, I think it'd be totally understandable to avoid the more complex matching path-to-regex enables and instead focus on primitive types i.e.
<Route path='/:param(number)' />
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions