import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
// 基础路由
const routes = [
{
path: "/",
name: "index",
component: () => import("../views/index/index")
},
{
path: "/page",
name: "page",
component: () => import("../views/page/page")
}
];
const createRouter = () =>
new VueRouter({
mode: "hash",
base: process.env.BASE_URL,
routes
});
const router = createRouter();
// 路由重置
export function resetRouter() {
const initRouter = createRouter();
router.matcher = initRouter.matcher;
}
export default router;
用户登录后,进行权限验证,通过router.addRoutes()增加路由,用户登出后,通过上述resetRouter方法初始化路由即可。