Route Transitions and Animation
RouterView with Transition, transition-name based on route, slide/fade between routes.
Route Transitions and Animation is a free Vue Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, and your progress syncs across the web and the CoddyKit app. The Vue Academy course includes 4 lessons in total.
Animating Between Routes
When the URL changes, the matched component swaps instantly. By wrapping the view in Vue's Transition, you can fade or slide between pages for a smoother feel.
RouterView With v-slot
To animate, you need access to the resolved component. The scoped slot form of RouterView exposes Component and route.
<RouterView v-slot="{ Component }">
<component :is="Component" />
</RouterView>Wrapping With Transition
Place a Transition around the dynamic component. Vue applies enter/leave classes as the route component mounts and unmounts.
<RouterView v-slot="{ Component }">
<Transition name="fade" mode="out-in">
<component :is="Component" />
</Transition>
</RouterView>Why mode out-in?
Without mode, the old and new pages animate at the same time and overlap. mode="out-in" waits for the old page to leave before the new one enters.
Defining the CSS
The name becomes a CSS class prefix. Define enter and leave transitions for a fade.
<style>
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
</style>Per-Route Transition via Meta
Store a transition name in route meta so different routes animate differently — slide for one section, fade for another.
{ path: '/about', component: About, meta: { transition: 'slide' } }Computing the Transition Name
Read route.meta.transition from the slot and bind it to the Transition name, falling back to a default.
<RouterView v-slot="{ Component, route }">
<Transition :name="route.meta.transition || 'fade'" mode="out-in">
<component :is="Component" />
</Transition>
</RouterView>Directional Slides
You can pick the transition dynamically based on navigation direction — for example, slide left going forward and right going back — by comparing route depth in a guard.
Slide Enter and Leave
A slide combines opacity and transform. Move the entering page in from the right and the leaving page out to the left.
<style>
.slide-enter-active,
.slide-leave-active {
transition: all 0.3s ease;
}
.slide-enter-from { transform: translateX(30px); opacity: 0; }
.slide-leave-to { transform: translateX(-30px); opacity: 0; }
</style>Keying for Param Changes
If two routes share the same component (like /user/1 and /user/2), Vue reuses it and skips the transition. Add a :key on the route path to force re-render and animation.
<component :is="Component" :key="route.path" />Respecting Reduced Motion
For accessibility, disable animations when the user prefers reduced motion using a CSS media query.
<style>
@media (prefers-reduced-motion: reduce) {
.fade-enter-active, .fade-leave-active { transition: none; }
}
</style>Quick Check
Test your knowledge of route transitions.
Recap
You learned to animate routes:
- Use RouterView with v-slot to get Component and route.
- Wrap component :is with Transition and use mode="out-in".
- Define enter/leave CSS keyed on the transition name.
- Read route.meta.transition for per-route animations; add :key for shared components.
Learn HTML with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 42
- Lessons
- 156
Frequently Asked Questions
Is the “Route Transitions and Animation” lesson free?
Yes — any 3 lessons of the Vue Academy learning path, including “Route Transitions and Animation”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Vue Academy course includes 4 lessons in total.
What will I learn in “Route Transitions and Animation”?
RouterView with Transition, transition-name based on route, slide/fade between routes. You practise Vue Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Vue Academy?
No prior experience is required. Vue Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
How long does the “Route Transitions and Animation” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Vue Academy lesson?
Yes. Every Vue Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Route Meta Fields and Typing
- Route Transitions and Animation
- Scroll Behavior Configuration
- Programmatic Navigation and useRouter