vue清除已经注册的路由

import store from '@/store'
import Router from 'vue-router'
import { constantRouterMap } from '@/router/routers'  //注册的路由定义名称
// 初始化路由
export const resetRouter = (router) => {
  const createRouter = () =>
    new Router({
      mode: 'history',
      routes: constantRouterMap
    })
  // 用初始化的matcher替换当前router的matcher
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

调用方法:

resetRouter(this.$router)

参考constantRouterMap :
import { constantRouterMap } from ‘@/router/routers’ //注册的路由定义名称
vue清除已经注册的路由_第1张图片

你可能感兴趣的:(vue.js,前端)