Fix: 修正重定向逻辑 & 使用Pinia管理状态
This commit is contained in:
@ -33,4 +33,28 @@ router.isReady().then(() => {
|
||||
localStorage.removeItem('vuetify:dynamic-reload')
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 如果访问根路径且不是直接输入地址访问
|
||||
if (to.path === '/' && from.path !== '/') {
|
||||
// 检查是否有保存的路径
|
||||
const lastRoute = sessionStorage.getItem('lastRoute')
|
||||
const savedPath = localStorage.getItem('lastPath')
|
||||
|
||||
if (lastRoute || savedPath) {
|
||||
// 重定向到上次访问的页面
|
||||
next(lastRoute || savedPath || '/calculators/paper-tube-weight')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 保存当前路由(非首页)
|
||||
if (to.path !== '/') {
|
||||
sessionStorage.setItem('lastRoute', to.fullPath)
|
||||
localStorage.setItem('lastPath', to.fullPath)
|
||||
}
|
||||
|
||||
next()
|
||||
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user