Sub RouterView component will render multiple times when using with KeepAlive
Version
3.2.19
Reproduction link
Steps to reproduce
- Visit
Home
Page. - Jump to the
About
Page. - Click button to render
Sub
Page.
What is expected?
Sub
Page component render only once. The create
hook called once.
What is actually happening?
Sub
Page component render twice, and the created
hook called twice.
I have did some research about this issue, hope it helps.
Since the Home
Page is keep-alived,so when jump to the About
Page, the Home
Page won't be unmounted, and the render effect of the Home
Page's sub RouterView
won't be cleared.
And then when we click this button, the currentRoute
of our router
changed, which will trigger all the RouterView
to be re rendered. Under normal conditions, the RouterView
component inside About
component will be render as the Sub
component. But unfortunately, the RouterView
component inside Home component also be re rendered as the Sub
component.
Duplicate of https://github.com/vuejs/vue-router-next/issues/626