From 98e60a89298459341530d42fce3195b133cd8629 Mon Sep 17 00:00:00 2001 From: oat_dev Date: Tue, 2 Jul 2024 16:43:44 +0700 Subject: [PATCH] fix: correct path but not found --- src/modules/router.ts | 13 +++++++++++-- src/views/Error404NotFound.vue | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/modules/router.ts b/src/modules/router.ts index 185a0e3f..1b9216d5 100644 --- a/src/modules/router.ts +++ b/src/modules/router.ts @@ -1,7 +1,12 @@ import type { RouteRecordRaw } from "vue-router"; +// import { ref } from "vue"; +// import { useRoute } from "vue-router"; const Error404NotFound = () => import("@/views/Error404NotFound.vue"); const data = await fetch("/toc.json").then((r) => r.json()); +// const routes = useRoute(); +// const hasQueryParam = ref(false); +const mainDataInfo = data.filter((v: any) => v.path); const manual = data.filter((v: any) => v.children); const mergeManual: any[] = []; @@ -24,7 +29,10 @@ const route: RouteRecordRaw[] = [ name: "Manual", component: () => import("@/modules/01_manual/MainPage.vue"), beforeEnter: (to, from, next) => { - const itemExists = manualRoute.some((item) => item.path === to.fullPath); + const mergeAll = [...mainDataInfo, ...manualRoute]; + const itemExists = mergeAll.some( + (item) => item.path === window.location.pathname + ); if (itemExists) { next(); @@ -32,6 +40,7 @@ const route: RouteRecordRaw[] = [ next({ name: "Error404NotFound", params: { pathMatch: to.path.substring(1).split("/") }, + query: to.query, }); } }, @@ -55,7 +64,7 @@ const route: RouteRecordRaw[] = [ path: "/:pathMatch(.*)*", name: "Error404NotFound", component: Error404NotFound, - props: true, + props: (route) => ({ query: route.query }), }, ]; diff --git a/src/views/Error404NotFound.vue b/src/views/Error404NotFound.vue index abb6caa7..946bae56 100644 --- a/src/views/Error404NotFound.vue +++ b/src/views/Error404NotFound.vue @@ -4,6 +4,12 @@ import { useRoute } from "vue-router"; export default defineComponent({ name: "Error404NotFound", + // props: { + // query: { + // type: Object, + // default: () => ({}), + // }, + // }, setup() { const route = useRoute(); const hasQueryParam = ref(false);