Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
mlaj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-09-22 14:17:43 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f9efa02599571582122d04172657a2cded4e1e33
f9efa025
1 parent
6a17cf01
fix(router): 修复登录状态检查并优化滚动行为
移除未使用的滚动位置参数并简化滚动到顶部逻辑 添加已登录用户访问登录页时的重定向逻辑
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
src/router/index.js
src/router/index.js
View file @
f9efa02
...
...
@@ -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
()
})
...
...
Please
register
or
login
to post a comment