I am using Vue, Vuex, and Vue-router. There is a list of router-link elements. When clicked, the component in the router-view area should switch with animation and the route url should change. In other words, the old component should disappear completely, then there is a request to the server for data for the new component, and then the new component appears smoothly. But this does not happen. After clicking on the router-link, the data for the new route is loaded quickly and the NEW component disappears smoothly, then it appears smoothly.
What am I doing wrong that a new component disappears? I make a request for data in the beforeRouteEnter and beforeRouteUpdate hooks.
LessonsList.vue
<template>
<section>
<ul>
<router-link
v-for="(lesson,index) in lessons"
v-bind:key="index"
:to="{
name: 'lesson',
params: {
id: index+1
}
}"
tag="li"
>
<h2>№{{index+1}}</h2>
</router-link>
</ul>
<transition name="slide" mode="out-in" appear>
<router-view :key="$route.path"></router-view>
</transition>
</section>
Lesson.vue
import {store} from '../../vuex/store'
beforeRouteEnter(to, from, next) {
let sendData = {};
sendData.lessonNumber = Number(to.params.id);
sendData.userId = store.getters['login/userId'];
store.dispatch('lesson/changeCurrentLesson', sendData).then(()=> next());
//dispatch action to vuex for data fetching
},
beforeRouteUpdate(to, from, next){
let sendData = {};
sendData.lessonNumber = Number(to.params.id);
sendData.userId = store.getters['login/userId'];
store.dispatch('lesson/changeCurrentLesson', sendData).then(()=> next());
}