Documentation Index
Fetch the complete documentation index at: https://mintlify.com/apursley2012/webmaster/llms.txt
Use this file to discover all available pages before exploring further.
PageTransition is a thin wrapper around Framer Motion’s motion.div that gives every route change a smooth fade-and-slide feel. When a new page enters, it slides up from 20px below, fades in, and scales from 0.98 to full size. When a page exits, it slides up a further 20px, fades out, and scales back down slightly. The AnimatePresence mode="wait" at the router level ensures the outgoing page finishes its exit animation before the incoming page begins — preventing any visual overlap between routes.
Props
The page component to animate. Wrap each route’s element with
<PageTransition> so every route gets its own motion.div lifecycle.Animation Values
The component passes the following variant objects directly tomotion.div:
| Prop | Value | Description |
|---|---|---|
initial | { opacity: 0, y: 20, scale: 0.98 } | Page starts invisible, offset 20px below and very slightly scaled down |
animate | { opacity: 1, y: 0, scale: 1 } | Page fades in, slides up to its natural position, and scales to full size |
exit | { opacity: 0, y: -20, scale: 0.98 } | Page fades out while continuing to slide upward and shrinking slightly |
transition | { duration: 0.4, ease: 'easeOut' } | 400ms ease-out on both enter and exit |
y: 20 on enter and y: -20 on exit creates a continuous upward momentum — each page flows naturally out of the one before it.
Core Implementation
Router-Level Setup
AnimatePresence must wrap the <Routes> block, not individual components. Setting mode="wait" tells Framer Motion to complete the current page’s exit animation before mounting the next page’s initial state — without this, both pages would be in the DOM simultaneously and the transitions would overlap.
The key={location.pathname} on <Routes> is essential: it signals to AnimatePresence that the child tree has changed when the URL changes, triggering the exit/enter lifecycle.
The
location prop on <Routes> and the matching key are both required. If you omit key={location.pathname}, React will reuse the same Routes element between navigations and AnimatePresence will never see a child unmount — meaning exit animations will never fire.Dependency
PageTransition requires Framer Motion, which is already installed in the Webmaster project:
motion components and AnimatePresence are imported directly from the framer-motion package.
How AnimatePresence mode="wait" Works
Key change detected
The
key={location.pathname} on <Routes> changes, so React unmounts the old Routes tree and mounts a new one. AnimatePresence intercepts the unmount.Exit animation plays
The outgoing page’s
motion.div animates to { opacity: 0, y: -20, scale: 0.98 } over 400ms. The element stays in the DOM until the animation completes.