#astro
2 messages · Page 1 of 1 (latest)
Astro supports opt-in, per-page view transitions that allow for seamless animations between pages without a full browser refresh. Here are the key points about Astro's view transitions:
-
View transitions are enabled by adding the
<ClientRouter />component to a page's<head>. This component provides a lightweight client-side router for customizing page transitions. -
You can add view transitions to individual pages or site-wide by including the
<ClientRouter />component in a common layout. -
Astro provides built-in animation options like
fade,slide, andnone, which can be customized using thetransition:animatedirective. -
You can control element matching between pages using the
transition:namedirective. -
The
transition:persistdirective allows you to maintain state for components across page navigations. -
Astro handles fallback behavior for browsers that don't support the View Transitions API.
To add view transitions to a page, you can use the following code:
---
import { ClientRouter } from 'astro:transitions';
---
<html lang="en">
<head>
<title>My Homepage</title>
<ClientRouter />
</head>
<body>
<h1>Welcome to my website!</h1>
</body>
</html>