hookehuyr

fix(router): 修复登录状态检查并优化滚动行为

移除未使用的滚动位置参数并简化滚动到顶部逻辑
添加已登录用户访问登录页时的重定向逻辑
......@@ -12,9 +12,8 @@ import { checkWxAuth, checkAuth } from './guards'
const router = createRouter({
history: createWebHashHistory(import.meta.env.VITE_BASE || '/'),
routes,
scrollBehavior(to, from, savedPosition) {
scrollBehavior() {
// 每次路由切换后,页面滚动到顶部
// return savedPosition || { top: 0, left: 0 }
return { top: 0, left: 0 }
},
})
......@@ -29,13 +28,20 @@ router.beforeEach(async (to, from, next) => {
}
// 检查用户是否已登录
const currentUser = JSON.parse(localStorage.getItem('currentUser') || 'null')
// 登录权限检查
const authResult = checkAuth(to)
if (authResult !== true) {
next(authResult)
return
}
// 如果用户已经在登录页面,但已经登录了,重定向到首页
if (to.path === '/login' && currentUser) {
next('/')
return
}
next()
})
......