Author -  Sai gowtham

How to create Vue router transitions

In this tutorial, we are going to learn about how to create transitions between routes in our vue app.

Vue.js provides us a <transistion> component by wrapping that component with <router-view> we can easily add transitions to routes.

Note: This tutorial assumes that you already familiar with Vue transitions. If you don’t know about how transitions work in Vue then check out Intro to Vue.js transitions

App.vue
<template>
  <div id="app">
    <ul>
      <router-link to="/">Home</router-link>
      <router-link to="/user">User</router-link>
      <router-link to="/contact">Contact us</router-link>
    </ul>
    <transition>      <router-view class="view"/>    </transition>  </div>
</template>

<script>
export default {};
</script>

In the above example, we wrapped our <router-view> component with <transistion> component but still we didn’t see any transitions because we need to add a name attribute with transition class name to <transistion> component.

Slide transition example

App.vue
<template>
  <div id="app">
    <ul>
      <router-link to="/">Home</router-link>
      <router-link to="/user">User</router-link>
      <router-link to="/contact">Contact us</router-link>
    </ul>
    <transition name="slide" mode="out-in">      <router-view class="view"/>
    </transition>
  </div>
</template>

<script>
export default {};
</script>

<style>

/*slide transition*/.slide-enter-active,.slide-leave-active {  transition: transform 0.4s ease-out;}.slide-enter {  transform: translateX(-30%);}.slide-leave-to {  transform: translateX(30%);}</style>

Here we also added mode='out-in' attribute where out-in means the old component is removed first before adding a new component.

vue-router-slide-transition-example

Flip transition example

Let’s add a flip transition effect to our routes by removing slide transition.

App.vue
<template>
  <div id="app">
    <ul>
      <router-link to="/">Home</router-link>
      <router-link to="/user">User</router-link>
      <router-link to="/contact">Contact us</router-link>
    </ul>
    <transition name="flip" mode="out-in">      <router-view class="view"/>
    </transition>
  </div>
</template>

<script>
export default {};
</script>

<style>
/*flip transition*/
.flip-enter-active,.flip-leave-active {  transition: transform 0.3s ease-out;}.flip-enter {  transform: rotateY(90deg);}.flip-leave-to {  transform: rotateY(90deg);}</style>

vue-router-flip-transition-example

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY