vue router 动态路由清除方式,resetRouter不起作用

背景:vue项目使用vue router退出登录后路由没有被清除

官方给到的resetRouter内初始化的matcher替换当前router的matcher不起作用

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    
    
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

解决方案

退出登录时直接刷新当前页面

this.$router.replace({
    
    path: '/login'});
location.reload();

简单粗暴且有效

猜你喜欢

转载自blog.csdn.net/gjwgjw1111/article/details/131132600