hrms-manual/src/modules/router.ts

88 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-05-29 14:06:59 +07:00
import type { RouteRecordRaw } from "vue-router";
2024-07-02 16:43:44 +07:00
// import { ref } from "vue";
// import { useRoute } from "vue-router";
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
2024-06-28 13:58:31 +07:00
const data = await fetch("/toc.json").then((r) => r.json());
2024-07-02 16:43:44 +07:00
// const routes = useRoute();
// const hasQueryParam = ref<boolean>(false);
const mainDataInfo = data.filter((v: any) => v.path);
2024-06-28 13:58:31 +07:00
const manual = data.filter((v: any) => v.children);
const mergeManual: any[] = [];
2024-11-19 13:29:14 +07:00
manual.forEach((v: any) => {
if (v.children) {
v.children.forEach((i: any) => {
if (i.children) {
i.children.forEach((item: any) => {
if (item.children) {
mergeManual.push(...item.children);
} else {
mergeManual.push(item);
}
});
} else {
mergeManual.push(i);
}
});
}
});
2024-06-28 13:58:31 +07:00
const manualRoute = mergeManual.map(
(v): { path: string; name: string; component: Function } => {
return {
path: v.path,
name: "Manual",
component: () => import("@/modules/01_manual/MainPage.vue"),
};
}
);
2024-06-24 13:07:27 +07:00
const route: RouteRecordRaw[] = [
2023-09-06 14:51:44 +07:00
{
2024-05-29 14:06:59 +07:00
path: "/manual/:name",
name: "Manual",
component: () => import("@/modules/01_manual/MainPage.vue"),
beforeEnter: (to, from, next) => {
2024-07-02 16:43:44 +07:00
const mergeAll = [...mainDataInfo, ...manualRoute];
const itemExists = mergeAll.some(
(item) => item.path === window.location.pathname
);
if (itemExists) {
next();
} else {
2024-07-01 10:21:21 +07:00
next({
name: "Error404NotFound",
params: { pathMatch: to.path.substring(1).split("/") },
2024-07-02 16:43:44 +07:00
query: to.query,
2024-07-01 10:21:21 +07:00
});
}
},
},
2024-06-24 13:07:27 +07:00
{
2024-07-01 10:21:21 +07:00
path: "/build-and-deploy",
name: "BuildAndDeploy",
2024-06-24 13:07:27 +07:00
component: () => import("@/modules/02_pages/MainPage.vue"),
},
2024-07-01 10:21:21 +07:00
{
path: "/debug",
name: "Debug",
component: () => import("@/modules/02_pages/MainPage.vue"),
},
// {
// path: "/:name",
// name: "Pages",
// component: () => import("@/modules/02_pages/MainPage.vue"),
// },
{
path: "/:pathMatch(.*)*",
name: "Error404NotFound",
component: Error404NotFound,
2024-07-02 16:43:44 +07:00
props: (route) => ({ query: route.query }),
},
2024-06-24 13:07:27 +07:00
];
export default route;