2023-04-20 08:04:08 +00:00
|
|
|
import {
|
|
|
|
type RouteRecordRaw,
|
|
|
|
createRouter,
|
|
|
|
createWebHashHistory,
|
|
|
|
createWebHistory,
|
|
|
|
} from "vue-router";
|
|
|
|
|
|
|
|
/** 常驻路由 */
|
|
|
|
export const constantRoutes: RouteRecordRaw[] = [
|
|
|
|
{
|
2023-05-01 15:06:46 +00:00
|
|
|
name: "Topic",
|
2023-04-20 08:04:08 +00:00
|
|
|
path: "/topic",
|
2023-05-01 15:06:46 +00:00
|
|
|
// 路由懒加载
|
2023-04-20 15:34:48 +00:00
|
|
|
component: () => import("@/views/topic/KUNGalgameTopicPage.vue"),
|
|
|
|
},
|
|
|
|
{
|
2023-05-01 15:06:46 +00:00
|
|
|
name: "KUN",
|
2023-04-20 15:34:48 +00:00
|
|
|
path: "/",
|
|
|
|
component: () => import("@/views/Home/KUNGalgameMainPage.vue"),
|
2023-04-20 08:04:08 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
history:
|
|
|
|
import.meta.env.VITE_ROUTER_HISTORY === "hash"
|
|
|
|
? createWebHashHistory(import.meta.env.VITE_PUBLIC_PATH)
|
|
|
|
: createWebHistory(import.meta.env.VITE_PUBLIC_PATH),
|
|
|
|
routes: constantRoutes,
|
|
|
|
});
|
|
|
|
|
|
|
|
/** 重置路由 */
|
|
|
|
export function resetRouter() {
|
|
|
|
// 注意:所有动态路由路由必须带有 Name 属性,否则可能会不能完全重置干净
|
|
|
|
try {
|
|
|
|
router.getRoutes().forEach((route: { name: any; meta: any }) => {
|
|
|
|
const { name, meta } = route;
|
|
|
|
if (name && meta.roles?.length) {
|
|
|
|
router.hasRoute(name) && router.removeRoute(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
// 强制刷新浏览器也行,只是交互体验不是很好
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default router;
|