react-router-dom
Advanced tools
Changelog
v6.17.0
Date: 2023-10-16
We're excited to release experimental support for the View Transitions API in React Router! You can now trigger navigational DOM updates to be wrapped in document.startViewTransition
to enable CSS animated transitions on SPA navigations in your application.
The simplest approach to enabling a View Transition in your React Router app is via the new <Link unstable_viewTransition>
prop. This will cause the navigation DOM update to be wrapped in document.startViewTransition
which will enable transitions for the DOM update. Without any additional CSS styles, you'll get a basic cross-fade animation for your page.
If you need to apply more fine-grained styles for your animations, you can leverage the unstable_useViewTransitionState
hook which will tell you when a transition is in progress and you can use that to apply classes or styles:
function ImageLink(to, src, alt) {
const isTransitioning = unstable_useViewTransitionState(to);
return (
<Link to={to} unstable_viewTransition>
<img
src={src}
alt={alt}
style={{
viewTransitionName: isTransitioning ? "image-expand" : "",
}}
/>
</Link>
);
}
You can also use the <NavLink unstable_viewTransition>
shorthand which will manage the hook usage for you and automatically add a transitioning
class to the <a>
during the transition:
a.transitioning img {
view-transition-name: "image-expand";
}
<NavLink to={to} unstable_viewTransition>
<img src={src} alt={alt} />
</NavLink>
For an example usage of View Transitions, check out our fork of the awesome Astro Records demo.
For more information on using the View Transitions API, please refer to the Smooth and simple transitions with the View Transitions API guide from the Google Chrome team.
ScrollRestoration
when sessionStorage
is unavailable (#10848)RouterProvider
future
prop type to be a Partial<FutureConfig>
so that not all flags must be specified (#10900)ErrorResponse
type to avoid leaking internal field (#10876)Full Changelog: 6.16.0...6.17.0
Changelog
v6.16.0
Date: 2023-09-13
any
with unknown
on exposed typings for user-provided data. To do this in Remix v2 without introducing breaking changes in React Router v6, we have added generics to a number of shared types. These continue to default to any
in React Router and are overridden with unknown
in Remix. In React Router v7 we plan to move these to unknown
as a breaking change. (#10843)
Location
now accepts a generic for the location.state
valueActionFunctionArgs
/ActionFunction
/LoaderFunctionArgs
/LoaderFunction
now accept a generic for the context
parameter (only used in SSR usages via createStaticHandler
)useMatches
(now exported as UIMatch
) accepts generics for match.data
and match.handle
- both of which were already set to unknown
@private
class export ErrorResponse
to an UNSAFE_ErrorResponseImpl
export since it is an implementation detail and there should be no construction of ErrorResponse
instances in userland. This frees us up to export a type ErrorResponse
which correlates to an instance of the class via InstanceType
. Userland code should only ever be using ErrorResponse
as a type and should be type-narrowing via isRouteErrorResponse
. (#10811)ShouldRevalidateFunctionArgs
interface (#10797)_isFetchActionRedirect
, _hasFetcherDoneAnything
) (#10715)query
/queryRoute
calls (#10793)route.lazy
routes (#10778)actionResult
on the arguments object passed to shouldRevalidate
(#10779)Full Changelog: v6.15.0...v6.16.0