feat: redirect to 404 when unknown path
This commit is contained in:
parent
be75902c5e
commit
2495100ee3
1 changed files with 21 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import type { RouteRecordRaw } from "vue-router";
|
import type { RouteRecordRaw } from "vue-router";
|
||||||
|
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
|
||||||
const data = await fetch("/toc.json").then((r) => r.json());
|
const data = await fetch("/toc.json").then((r) => r.json());
|
||||||
|
|
||||||
const manual = data.filter((v: any) => v.children);
|
const manual = data.filter((v: any) => v.children);
|
||||||
|
|
@ -20,16 +20,36 @@ const manualRoute = mergeManual.map(
|
||||||
|
|
||||||
const route: RouteRecordRaw[] = [
|
const route: RouteRecordRaw[] = [
|
||||||
// ...manualRoute,
|
// ...manualRoute,
|
||||||
|
// {
|
||||||
|
// path: "/manual/chapter-1-admin-login",
|
||||||
|
// name: "Manual",
|
||||||
|
// component: () => import("@/modules/01_manual/MainPage.vue"),
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
path: "/manual/:name",
|
path: "/manual/:name",
|
||||||
name: "Manual",
|
name: "Manual",
|
||||||
component: () => import("@/modules/01_manual/MainPage.vue"),
|
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",
|
path: "/:name",
|
||||||
name: "Pages",
|
name: "Pages",
|
||||||
component: () => import("@/modules/02_pages/MainPage.vue"),
|
component: () => import("@/modules/02_pages/MainPage.vue"),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/:pathMatch(.*)*",
|
||||||
|
name: "Error404NotFound",
|
||||||
|
component: Error404NotFound,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default route;
|
export default route;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue