You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionApp(){return(<Routes><Routepath="en"element={<Langlang="en"/>}/><Routepath="es"element={<Langlang="es"/>}/><Routepath="fr"element={<Langlang="fr"/>}/></Routes>);}functionLang({ lang }){lettranslations=I81n[lang];// ...}
My proposal is to support named static path segments that are added to the params object, for example
functionApp(){return(<Routes><Routepath="(:country)en"element={<Lang/>}/><Routepath="(:country)es"element={<Lang/>}/><Routepath="(:country)fr"element={<Lang/>}/></Routes>);}functionLang(){const{ country }=useParams()}
The benefits are
you don't need prop drilling or context for (deeply) nested components - you can just use useParams in the nested components.
you would have access to the value in loaders via params
EDIT: our use-case for static portions of the url is to support optional segments earlier in the path and make them unambiguous, for example
where we'd typically create the routes using something along the lines of ['en','es,'fr'].map((country) => <Route path=`/some-static-part/:variableA/:variableB?/(:country)${country}`).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As part of upgrading from v5 to v6, I am dealing with removing regular expressions in routes and the situation I have come across is static values in paths, such as the example from https://reactrouter.com/6.28.0/start/faq#what-happened-to-regexp-routes-paths
with the recommended change to be
My proposal is to support named static path segments that are added to the
params
object, for exampleThe benefits are
useParams
in the nested components.loaders
viaparams
EDIT: our use-case for static portions of the url is to support optional segments earlier in the path and make them unambiguous, for example
where I'd like to be able to use have
where we'd typically create the routes using something along the lines of
['en','es,'fr'].map((country) => <Route path=`/some-static-part/:variableA/:variableB?/(:country)${country}`)
.Beta Was this translation helpful? Give feedback.
All reactions