Vue3 router – view keep active:
<router-view v-slot="{ Component, route }">
<keep-alive :include="includeList">
<component
:is="Component"
:key="route.name"
v-if="includeList.includes(route.name)"
/>
</keep-alive>
<component
:is="Component"
:key="route.name"
v-if="(!includeList.includes(route.name) && !route.meta.keepAlive)"
/>
</router-view>
- First of all, make sure that the
include
passed value is the three forms in the official document: keep-alive - Make sure that the
<component>
corresponding component is definedname
(<script setup>
syntactic sugar cannot be definedname
, you need to change it to a non-syntactic sugar form, choose yourself)