How to handle transitions between routes in Vue.js?

Vue Router allows you to add transitions between routes using the <transition> element.

<!-- App.vue -->
<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'App',
};
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}
</style>

You can then define transitions in individual components or use a global transition for all routes.

Post your Answer