Replies: 1 comment
-
Another possible option is to add context to the route, e.g. function App() {
return createRoutesFromElements(
<Routes>
<Route path="en" context={{country: 'en'}} lazy={() => import("./language")} />
<Route path="es" context={{country: 'es'}} lazy={() => import("./language")} />
<Route path="fr" context={{country: 'fr'}} lazy={() => import("./language")} />
</Routes>
);
}
// language.js
function Lang() {
const { country } = useRouteContext() // new hook
...
}
function loader: ({ routeContext }) {
const { country } = routeContext
return api.getCountryStuff(country);
} Perhaps this is the use-case for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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