如何强制 Vue 在路由更改时销毁并重新创建组件?

How to force Vue to destroy and re-create the component on route change?

我在 Vue 路由器中的路由:

{ path: 'articles/create', component: () => import('Detail.vue') },
{ path: 'articles/:id/edit', component: () => import('Detail.vue') },

如您所见,我在两条路线上渲染了相同的 Vue 组件 Detail.vue

当 URL 发生变化时 例如 /articles/5/edit,我如何“强制”Vue 销毁并重新创建 Detail.vue 组件 ] 到 /articles/create ?

<router-view :key="$route.fullPath" />

请注意,这只会强制路由器到 destroy/create 组件,对路由器挂钩没有影响 - 例如 beforeEnter 挂钩不会被调用,即使目标组件已被销毁并且新组件已创建创建...