Transition and conditionally KeepAlive can't work at the same time with a <div> as child component of Transition #1968
-
Reproductionhttps://codesandbox.io/p/sandbox/nostalgic-bardeen-jvmjpv?file=%2Fsrc%2FApp.vue%3A30%2C38 Steps to reproduce the bug <!-- keep-alive doesn't work -->
<RouterView v-slot="{ Component, route }">
<Transition name="fade">
<div :key="route.fullPath" class="w-full h-full">
<KeepAlive>
<component
:is="Component"
v-if="route.meta.keepAlive"
:key="route.fullPath"
/>
</KeepAlive>
<component :is="Component" v-if="!route.meta.keepAlive" />
</div>
</Transition>
</RouterView> <!-- remove key in div, keep-alive works, but transition doesn't work -->
<RouterView v-slot="{ Component, route }">
<Transition name="fade">
<div class="w-full h-full">
<KeepAlive>
<component
:is="Component"
v-if="route.meta.keepAlive"
:key="route.fullPath"
/>
</KeepAlive>
<component :is="Component" v-if="!route.meta.keepAlive" />
</div>
</Transition>
</RouterView> Because the I need the Expected behavior
Actual behavior
Additional informationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Transition needs single root components. |
Beta Was this translation helpful? Give feedback.
-
I have some nested routes: {
path: "/a",
name: "a",
component: () => import("../views/A.vue"),
redirect: "/a/a1",
children: [
{
path: "a1",
component: () => import("../views/A1.vue"),
},
{
path: "a2",
component: () => import("../views/A2.vue"),
},
],
} App.vue <RouterView v-slot="{ Component, route }">
<Transition name="slide-right">
<KeepAlive :include="['A1']">
<component :is="Component" :key="route.fullPath" />
</KeepAlive>
</Transition>
</RouterView> A.vue <router-view v-slot="{ Component, route }">
<keep-alive :include="['A1']">
<component :is="Component" :key="route.fullPath" />
</keep-alive>
</router-view> I only want to cache If i changed include prop to @posva Please help me look at this problem. Thanks ❤️ ❤️ ❤️ |
Beta Was this translation helpful? Give feedback.
-
I was facing the same problem trying to implement the conditional <RouterView v-slot="{ Component, route }">
<Transition name="page-slide" mode="out-in">
<KeepAlive :include="route.meta.keepAlive ? Component.type.__name : null">
<component :is="Component" :key="route.fullPath" />
</KeepAlive>
</Transition>
</RouterView> |
Beta Was this translation helpful? Give feedback.
Second version is correct. You need to ensure that your page components are single root in order to use transition