View transitions
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Astro supports view transitions with just a few lines of code. View transitions update your page content without the browser’s normal, full-page navigation refresh and provide seamless animations between pages. Where browser support for the View Transition API is lacking, Astro allows you to control fallback strategies for the best possible experience for all visitors.
Astro provides a <ClientRouter />
routing component that can be added to a single page’s <head>
to control page transitions as you navigate away to another page. It provides a lightweight client-side router that intercepts navigation and allows you to customize the transition between pages.
Add this component to a reusable .astro
component, such as a common head or layout, for animated page transitions across your entire site (SPA mode).
Astro’s view transitions support is powered by the new View Transitions browser API and also includes:
- A few built-in animation options, such as
fade
,slide
, andnone
. - Support for both forwards and backwards navigation animations.
- The ability to fully customize all aspects of transition animation, and build your own animations.
- The option to prevent client-side navigation for non-page links.
- Control over fallback behavior for browsers that do not yet support the View Transition APIs.
- Automatic support for
prefers-reduced-motion
.
By default, every page will use regular, full-page, browser navigation. You must opt in to view transitions and can use them either on a per-page basis or site-wide.
Adding View Transitions to a Page
Section titled Adding View Transitions to a PageOpt in to using view transitions on individual pages by importing and adding the <ClientRouter />
routing component to <head>
on every desired page.
---import { ClientRouter } from "astro:transitions";---<html lang="en"> <head> <title>My Homepage</title> <ClientRouter /> </head> <body> <h1>Welcome to my website!</h1> </body></html>