From ddd467b8cf6f7dc73a7f2abb5ec97e86c5cc334d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Mon, 3 Nov 2025 11:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=96=B0=E8=BF=9B=E5=85=A5=E9=A6=96?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/router/index.ts b/src/router/index.ts index 8f66ca3..cd761f8 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -11,6 +11,21 @@ const router = createRouter({ scrollBehavior: () => ({ left: 0, top: 0 }) }) + +// 监听页面刷新事件 +window.addEventListener('beforeunload', () => { + // 可以在这里做一些清理工作 + sessionStorage.setItem('shouldRedirectToHome', 'true') +}) + +// 页面加载完成后检查是否需要重定向 +router.isReady().then(() => { + if (sessionStorage.getItem('shouldRedirectToHome')) { + sessionStorage.removeItem('shouldRedirectToHome') + router.push('/index') // 或者你的主页路径 + } +}) + export const resetRouter = (): void => { const resetWhiteNameList = ['Redirect', 'Login', 'NoFind', 'Root'] router.getRoutes().forEach((route) => {