如何重置路由实例
首先先定义一个创建路由实例的函数:
// 定义一个创建路由的函数 const createRouter = () => new Router({ mode: "hash", // mode: "history", // require service support // base: "/hr", // 路由基准地址 这是历史模式使用的 为了防止后端路径冲突 scrollBehavior: () => ({ y: 0 }), // routes: constantRoutes, // constantRoutes静态路由映射 // routes: [...constantRoutes, ...asyncRoutes], // 静态+动态 放在一起 routes: [...constantRoutes], // 只有静态 放在一起 动态路由后i按根据用户权限控制添加动态路由 });
然后
// 重置路由实例的方法 // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465 export function resetRouter() { const newRouter = createRouter(); // 重新创建一个路由实例 router.matcher = newRouter.matcher; // 将新的路由实例的matcher属性赋给原来路由实例的matcher属性,即可实现原路由实例重置 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Blazor Hybrid适配到HarmonyOS系统
· 支付宝 IoT 设备入门宝典(下)设备经营篇
· 万字调研——AI生成内容检测
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库