From b40d6bffa4e2e8f2b6112f5d7496ae3ecf2f8f79 Mon Sep 17 00:00:00 2001 From: sendevia Date: Fri, 12 Dec 2025 16:29:38 +0800 Subject: [PATCH] refactor: redirection logic and add 404 page title handling --- .vitepress/theme/index.ts | 3 ++- .vitepress/theme/layouts/Default.vue | 20 ++++---------------- .vitepress/theme/layouts/NotFound.vue | 12 ++++++++++++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/.vitepress/theme/index.ts b/.vitepress/theme/index.ts index 9834663..9447e4b 100644 --- a/.vitepress/theme/index.ts +++ b/.vitepress/theme/index.ts @@ -23,12 +23,13 @@ export default { enhanceApp({ app }) { app.use(pinia); + app.component("MainLayout", Layout); + app.component("AppBar", AppBar); app.component("ArticleMasonry", ArticleMasonry); app.component("Footer", Footer); app.component("Header", Header); app.component("ImageViewer", ImageViewer); - app.component("MainLayout", Layout); app.component("MaterialButton", Button); app.component("MaterialCard", Card); app.component("NavBar", NavBar); diff --git a/.vitepress/theme/layouts/Default.vue b/.vitepress/theme/layouts/Default.vue index 388632e..5dc26f3 100644 --- a/.vitepress/theme/layouts/Default.vue +++ b/.vitepress/theme/layouts/Default.vue @@ -18,8 +18,6 @@ const currentRoutePath = ref(route.path); const pendingRoutePath = ref(null); const isRedirecting = ref(false); -let redirectTimer: ReturnType | null = null; - /** * 检查并执行重定向 * 返回 true 表示正在处理重定向 @@ -40,11 +38,9 @@ function checkAndRedirect(path: string): boolean { document.title = `跳转中 | ${site.value.title}`; } - redirectTimer = setTimeout(() => { - if (isClient()) { - window.location.replace(post.url); - } - }, 100); + if (isClient()) { + window.location.replace(post.url); + } return true; } @@ -107,10 +103,6 @@ watch( // 如果之前是重定向状态,清理状态 if (isRedirecting.value) { isRedirecting.value = false; - if (redirectTimer) { - clearTimeout(redirectTimer); - redirectTimer = null; - } } if (newPath !== oldPath && !isTransitioning.value && oldPath !== undefined) { @@ -145,11 +137,7 @@ if (isClient()) {