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’ //注册的路由定义名称