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) => {