VOOZH about

URL: https://blog.logrocket.com/creating-transitions-in-your-vue-app-with-vue-router/

⇱ Creating transitions in your Vue app with Vue Router - LogRocket Blog


2021-01-20
921
#vue
Emmanuel Akhigbe
32990
πŸ‘ Image

See how LogRocket's Galileo AI surfaces the most severe issues for you

No signup required

Check it out

πŸš€ Sign up for The Replay newsletter

The Replay is a weekly newsletter for dev and engineering leaders.

Delivered once a week, it's your curated guide to the most important conversations around frontend dev, emerging AI tools, and the state of modern software.

What is Vue Router?

Vue Router is the official routing library for Vue.js applications. Even though you can go ahead and use other generic routing libraries, Vue Router deeply integrates with the ideology of Vue.js to make Single Page Applications (SPAs) easy to build.

πŸ‘ The Vue logo against a dark background.

In this article, we will be looking at how to improve the user experience in your Vue applications easily by creating transitions while routing with Vue Router.

So, why use transitions in your app?

I’ll be talking a little bit about why you might need transitions in the first place.

A website is typically made up of a collection of web pages. Movement from one webpage to the other is pretty much unavoidable, and the interaction between the website and the page movement plays a fundamental role in shaping the experience that users have on our website.

As much as possible, we should build linearity into the interaction of our websites β€” when a user clicks a link, they should not feel like they are starting a new experience all over again. Instead, there should be a continued experience and build up.

Imagine going from chapter one in a book to chapter five without any linearity. Even though you may understand what chapter five talks about and eventually continue enjoying the book, there will be a break in the experience. This break in experience can be softened or even removed with the use of transitions.

Creating transitions

Vue Router makes it super easy to include transitions in your Vue app. In this article, we will be looking at how you can enable three delightful transitions in your Vue app. We will be working mainly with two components:

Transitions – Wrapper components from Vue that add transition effects to HTML or Vue elements whenever an element enters or leaves the DOM. In the <transition> component, the name attribute is used to add a transition class. Vue automatically gives us six classes prefixed with the value of the name attribute. These classes are applied during the life cycle of the transition. The classes can be broken into two groups depending on what happens when the element enters and leaves the DOM:

  • enter: This class defines the starting state of the element before it undergoes the transition. It is in effect just before the element is inserted
  • enter-active: This class defines what happens when the element is being inserted into the DOM. It can be used to define the duration of the entering transition
  • enter-to: This class defines what happens just after the element has been inserted into the DOM. It is removed once the entering transition finishes
  • leave: This class defines the leaving state of the element. It is in effect just before the element is removed from the DOM
  • leave-active: This class defines what happens during the element’s leaving phase. It can be used to define the duration of the leaving transition
  • leave-to: This class defines what happens just after the element has been removed from the DOM. It is removed once the removing transition finishes
  • router-view: This component is provided by Vue Router. It renders the component that matches a path specified in the Vue Router instantiation

Types of transition

  • Slide-fade
  • Fade
  • Custom transition classes

Note: This tutorial assumes you’re familiar with setting up a Vue application with Vue Router.

πŸ‘ A gif displaying how Vue slide fades transitions look for the user.

Slide fade transition example

App.vue

<template>
 <div id="app">
 <ul>
 <router-link to="/">Home</router-link>
 <router-link to="/about">About</router-link>
 <router-link to="/contact">Contact us</router-link>
 </ul>
 <transition name="slide-fade">
 <router-view class="view"/>
 </transition>
 </div>
</template>
<script>
 export default {}
</script>
<style>
.slide-fade-enter-active {
 transition: all .3s ease;
}
.slide-fade-leave-active {
 transition: all .8s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.slide-fade-enter, .slide-fade-leave-to{
 transform: translateX(10px);
 opacity: 0;
}
</style>

πŸ‘ A gif showing how the fade transition looks to the user in Vue.

Fade transition example

App.vue

<template>
 <div id="app">
 <ul>
 <router-link to="/">Home</router-link>
 <router-link to="/about">About</router-link>
 <router-link to="/contact">Contact us</router-link>
 </ul>
 <transition name="fade">
 <router-view class="view"/>
 </transition>
 </div>
</template>
<script>
export default {}
</script>
<style>
.fade-enter-active, .fade-leave-active {
 transition: opacity .4s;
}
.fade-enter, .fade-leave-to {
 opacity: 0;
}
</style>

πŸ‘ A gif displaying how the 'tada' transition works in Vue.

Custom transition classes

Add the animate.css CDN link to the HTML file in your public folder like so:

<link href="https://cdn.jsdelivr.net/npm/[email protected]" rel="stylesheet" type="text/css">

App.vue


Over 200k developers use LogRocket to create better digital experiences

πŸ‘ Image
Learn more β†’

<template>
 <div id="app">
 <ul>
 <router-link to="/">Home</router-link>
 <router-link to="/about">About</router-link>
 <router-link to="/contact">Contact us</router-link>
 </ul>
 <transition
 name="custom-classes-transition"
 enter-active-class="animated tada"
 leave-active-class="animated bounceOutRight"
 >
 <router-view class="view"/>
 </transition>
 </div>
</template>
 
<script>
export default {}
</script>
 
<style>
</style>

You can view more animation styles in the animate.css library here: animate.style.

Conclusion

In this article, we have looked at the different life cycles that are provided by the Vue Transition component and how to use them, we’ve also explored how to use them with other animation libraries like animate.css. You can read more in the documentation.

LogRocket understands everything users do in your Vue apps.

Debugging Vue.js applications can be difficult, especially when users experience issues that are difficult to reproduce. If you’re interested in monitoring and tracking Vue mutations and actions for all of your users in production, try LogRocket.

πŸ‘ LogRocket Dashboard Free Trial Banner

LogRocket lets you replay user sessions, eliminating guesswork by showing exactly what users experienced. It captures console logs, errors, network requests, and pixel-perfect DOM recordings β€” compatible with all frameworks.

With Galileo AI, you can instantly identify and explain user struggles with automated monitoring of your entire product experience.

Modernize how you debug your Vue apps β€” start monitoring for free.

πŸ‘ Image
πŸ‘ Image
πŸ‘ Image

Stop guessing about your digital experience with LogRocket

Get started for free

Recent posts:

What is TSRX?: What JSX would look like if it were designed today

TSRX adds first-class control flow, conditional hooks, and scoped styles to React via a TypeScript compiler extension β€” no new framework required.

πŸ‘ Image
Ikeh Akinyemi
Jun 12, 2026 β‹… 6 min read

How to add authentication to a React Native app with Better Auth

Learn how to build a full React Native auth system using Better Auth and Expo β€” with email/password login, Google OAuth, session persistence, and protected routes.

πŸ‘ Image
Chinwike Maduabuchi
Jun 9, 2026 β‹… 13 min read

AI dev tool power rankings & comparison [June 2026]

Compare the top AI development tools and models of June 2026. View updated rankings, feature breakdowns, and find the best fit for you.

πŸ‘ Image
Chizaram Ken
Jun 8, 2026 β‹… 11 min read

How to check username availability at scale with Bloom filters

Learn how Bloom filters reduce database lookups for username availability checks while preserving correctness at scale.

πŸ‘ Image
Rosario De Chiara
Jun 8, 2026 β‹… 6 min read
View all posts

Would you be interested in joining LogRocket's developer community?

Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now