keep-alive issues: Under keep-alive, the inactive RouterView child component gets replaced by the currently active sibling RouterView component at the same level. #14617
Replies: 2 comments
-
|
@WJ0527 What you’re running into is a known quirk of how Why it happens
SolutionYou need to give each <keep-alive>
<RouterView :key="$route.fullPath" />
</keep-alive>or, if you prefer route names: <keep-alive>
<RouterView :key="$route.name" />
</keep-alive>This ensures that when you navigate from Best practices
|
Beta Was this translation helpful? Give feedback.
-
|
This is expected if the thing being kept alive is the
The usual fix is to use the <RouterView v-slot="{ Component, route }">
<KeepAlive>
<component
:is="Component"
:key="route.name || route.fullPath"
/>
</KeepAlive>
</RouterView>For nested routes, apply the same idea at the level where you want caching: <RouterView v-slot="{ Component, route }">
<KeepAlive>
<component
:is="Component"
:key="route.fullPath"
/>
</KeepAlive>
</RouterView>The important distinction is: <!-- Avoid this -->
<KeepAlive>
<RouterView />
</KeepAlive><!-- Prefer this -->
<RouterView v-slot="{ Component, route }">
<KeepAlive>
<component :is="Component" :key="route.fullPath" />
</KeepAlive>
</RouterView>If So I would not expect an inactive cached |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions