diff --git a/packages/playground/src/App.vue b/packages/playground/src/App.vue
index 170d73919..14bfec956 100644
--- a/packages/playground/src/App.vue
+++ b/packages/playground/src/App.vue
@@ -158,6 +158,9 @@
/p_1/absolute-a
+
+ /func_comp
+
diff --git a/packages/playground/src/router.ts b/packages/playground/src/router.ts
index 981b4192f..9208162e6 100644
--- a/packages/playground/src/router.ts
+++ b/packages/playground/src/router.ts
@@ -12,6 +12,7 @@ const component = () => {
import LongView from './views/LongView.vue'
import GuardedWithLeave from './views/GuardedWithLeave.vue'
import ComponentWithData from './views/ComponentWithData.vue'
+import FuncComp from './views/FuncComp'
import { globalState } from './store'
import { scrollWaiter } from './scrollWaiter'
import RepeatedParams from './views/RepeatedParams.vue'
@@ -159,6 +160,10 @@ export const router = createRouter({
{ path: 'settings', component },
],
},
+ {
+ path: '/func_comp',
+ component: FuncComp,
+ },
],
async scrollBehavior(to, from, savedPosition) {
await scrollWaiter.wait()
diff --git a/packages/playground/src/views/FuncComp.ts b/packages/playground/src/views/FuncComp.ts
new file mode 100644
index 000000000..7266a8e28
--- /dev/null
+++ b/packages/playground/src/views/FuncComp.ts
@@ -0,0 +1,7 @@
+import { h, type FunctionalComponent } from 'vue'
+
+const FuncComp: FunctionalComponent = () => {
+ return h('div', {}, 'Demo Functional Component')
+}
+
+export default FuncComp
diff --git a/packages/router/src/RouterView.ts b/packages/router/src/RouterView.ts
index a456c2b63..a2e744ee2 100644
--- a/packages/router/src/RouterView.ts
+++ b/packages/router/src/RouterView.ts
@@ -160,7 +160,9 @@ export const RouterViewImpl = /*#__PURE__*/ defineComponent({
const onVnodeUnmounted: VNodeProps['onVnodeUnmounted'] = vnode => {
// remove the instance reference to prevent leak
- if (vnode.component!.isUnmounted) {
+ const component = vnode.component
+ // the component instance of functional component is null
+ if (!component || component.isUnmounted) {
matchedRoute.instances[currentName] = null
}
}