hrms-manual/src/modules/router.ts
2024-06-28 15:13:57 +07:00

55 lines
1.4 KiB
TypeScript

import type { RouteRecordRaw } from "vue-router";
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
const data = await fetch("/toc.json").then((r) => r.json());
const manual = data.filter((v: any) => v.children);
const mergeManual: any[] = [];
manual.forEach((v: any) => mergeManual.push(...v.children));
const manualRoute = mergeManual.map(
(v): { path: string; name: string; component: Function } => {
return {
path: v.path,
name: "Manual",
component: () => import("@/modules/01_manual/MainPage.vue"),
};
}
);
const route: RouteRecordRaw[] = [
// ...manualRoute,
// {
// path: "/manual/chapter-1-admin-login",
// name: "Manual",
// component: () => import("@/modules/01_manual/MainPage.vue"),
// },
{
path: "/manual/:name",
name: "Manual",
component: () => import("@/modules/01_manual/MainPage.vue"),
beforeEnter: (to, from, next) => {
const itemExists = manualRoute.some((item) => item.path === to.fullPath);
if (itemExists) {
console.log("Win");
next();
} else {
next({ name: "Error404NotFound" });
}
},
},
{
path: "/:name",
name: "Pages",
component: () => import("@/modules/02_pages/MainPage.vue"),
},
{
path: "/:pathMatch(.*)*",
name: "Error404NotFound",
component: Error404NotFound,
},
];
export default route;