0Pricing
Vue Academy · Lesson

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 — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Vue Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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.

Frequently asked questions

Is the “Route Transitions and Animation” lesson free?

Yes — the full text of “Route Transitions and Animation” is free to read here on the web, and the Vue Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Vue Academy course, upgrade to CoddyKit PRO.

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; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

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

  1. Route Meta Fields and Typing
  2. Route Transitions and Animation
  3. Scroll Behavior Configuration
  4. Programmatic Navigation and useRouter
← Back to Vue Academy