react-router-dom
Advanced tools
Changelog
v6.5.0
Date: 2022-12-16
This release introduces support for Optional Route Segments. Now, adding a ?
to the end of any path segment will make that entire segment optional. This works for both static segments and dynamic parameters.
Optional Params Examples
<Route path=":lang?/about>
will match:
/:lang/about
/about
<Route path="/multistep/:widget1?/widget2?/widget3?">
will match:
/multistep
/multistep/:widget1
/multistep/:widget1/:widget2
/multistep/:widget1/:widget2/:widget3
Optional Static Segment Example
<Route path="/home?">
will match:
/
/home
<Route path="/fr?/about">
will match:
/about
/fr/about
<Route path="prefix-:param">
, to align with how splat parameters work. If you were previously relying on this behavior then it's recommended to extract the static portion of the path at the useParams
call site: (#9506)// Old behavior at URL /prefix-123
<Route path="prefix-:id" element={<Comp /> }>
function Comp() {
let params = useParams(); // { id: '123' }
let id = params.id; // "123"
...
}
// New behavior at URL /prefix-123
<Route path=":id" element={<Comp /> }>
function Comp() {
let params = useParams(); // { id: 'prefix-123' }
let id = params.id.replace(/^prefix-/, ''); // "123"
...
}
headers
on loader
request
's after SSR document action
request (#9721)Full Changelog: v6.4.5...v6.5.0
Changelog
v6.4.5
Date: 2022-12-07
GET
request (#9680)instanceof Response
checks in favor of isResponse
(#9690)URL
creation in Cloudflare Pages or other non-browser-environments (#9682, #9689)requestContext
support to static handler query
/queryRoute
(#9696)
queryRoute(path, routeId)
has been changed to queryRoute(path, { routeId, requestContext })
Full Changelog: v6.4.4...v6.4.5
Changelog
v6.4.4
Date: 2022-11-30
action
/loader
function returns undefined
as revalidations need to know whether the loader has previously been executed. undefined
also causes issues during SSR stringification for hydration. You should always ensure your loader
/action
returns a value, and you may return null
if you don't wish to return anything. (#9511)basename
in static data routers (#9591)ErrorResponse
bodies to contain more descriptive text in internal 403/404/405 scenariosNavLink
and descendant <Routes>
(#9589, #9647)ErrorResponse
instances when using built-in hydration (#9593)basename
in static data routers (#9591)@remix-run/router@1.0.4
react-router@6.4.4
Full Changelog: v6.4.3...v6.4.4