@remix-run/router
shouldRevalidate
calls (#9948)
shouldRevalidate
function was only being called for explicit revalidation scenarios (after a mutation, manual useRevalidator
call, or an X-Remix-Revalidate
header used for cookie setting in Remix). It was not properly being called on implicit revalidation scenarios that also apply to navigation loader
revalidation, such as a change in search params or clicking a link for the page we're already on. It's now correctly called in those additional scenarios.current*
/next*
parameters reflected the static fetcher.load
URL (and thus were identical). Instead, they should have reflected the the navigation that triggered the revalidation (as the form*
parameters did). These parameters now correctly reflect the triggering navigation.preventScrollReset
on <fetcher.Form>
(#9963)instanceof
check from isRouteErrorResponse
to avoid bundling issues on the server (#9930)defer
call only contains critical data and remove the AbortController
(#9965)File
FormData
entries (#9867)createStaticHandler
(#9760)generatePath
when optional params are present (#9764)OPTIONS
requests in staticHandler.queryRoute
(#9914)shouldRevalidate
on action redirects (#9777, #9782)actionData
on action redirect to current location (#9772)unstable_
prefix from createStaticHandler
/createStaticRouter
/StaticRouterProvider
(#9738)replace
on submissions and PUSH
on submission to new paths (#9734)useLoaderData
usage in errorElement
(#9735)hydrationData
(#9664)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
lang?/about
will match:
/:lang/about
/about
/multistep/:widget1?/widget2?/widget3?
will match:
/multistep
/multistep/:widget1
/multistep/:widget1/:widget2
/multistep/:widget1/:widget2/:widget3
Optional Static Segment Example
/home?
will match:
/
/home
/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)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 })
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 you 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 scenarioscreateHashRouter
(#9409)basename
and relative routing in loader
/action
redirects (#9447)action
function (#9455)index
routes with a path
in useResolvedPath
(#9486)@remix-run/router
(#9446)createURL
in local file execution in Firefox (#9464)unstable_createStaticHandler
for incorporating into Remix (#9482, #9465)actionData
after a successful action redirect (#9334)matchPath
to avoid false positives on dash-separated segments (#9300)RouteObject
/RouteProps
types to surface the error in TypeScript. (#9366)initialEntries
(#9288)?index
for fetcher get submissions to index routes (#9312)This is the first stable release of @remix-run/router
, which provides all the underlying routing and data loading/mutation logic for react-router
. You should not be using this package directly unless you are authoring a routing library similar to react-router
.
For an overview of the features provided by react-router
, we recommend you go check out the docs, especially the feature overview and the tutorial.
For an overview of the features provided by @remix-run/router
, please check out the README
.