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-11-17 14:22:41 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a8eee9b1a8fa1836ec5cd922eaff74d3048a68d1
a8eee9b1
1 parent
b81a637e
fix(登录): 解码重定向参数并优化路由认证检查
修复登录后重定向参数未解码的问题,确保正确跳转 同时改进路由守卫逻辑,支持通过元信息检查认证需求
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
src/router/guards.js
src/views/auth/LoginPage.vue
src/router/guards.js
View file @
a8eee9b
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-
06-13 10:03:0
8
* @LastEditTime: 2025-
11-17 14:15:1
8
* @FilePath: /mlaj/src/router/guards.js
* @Description: 路由守卫逻辑
*/
...
...
@@ -22,6 +22,10 @@ export const authRequiredRoutes = [
path
:
'/activities/[^/]+/signup'
,
regex
:
true
,
},
{
path
:
'/checkin'
,
exact
:
false
,
},
]
// TAG: 微信授权检查
...
...
@@ -52,7 +56,8 @@ export const checkAuth = (to) => {
const
currentUser
=
JSON
.
parse
(
localStorage
.
getItem
(
'currentUser'
))
// 检查当前路由是否需要认证
const
needAuth
=
authRequiredRoutes
.
some
((
route
)
=>
{
// 方式一:白名单匹配(兼容旧逻辑)
const
needAuthByList
=
authRequiredRoutes
.
some
((
route
)
=>
{
// 如果是正则匹配模式
if
(
route
.
regex
)
{
return
new
RegExp
(
`^
${
route
.
path
}
$`).test(to.path)
...
...
@@ -64,6 +69,9 @@ export const checkAuth = (to) => {
// 默认前缀匹配模式
return to.path.startsWith(route.path)
})
// 方式二:读取路由元信息 requiresAuth(推荐)
const needAuthByMeta = to.matched.some(record => record.meta && record.meta.requiresAuth === true)
const needAuth = needAuthByList || needAuthByMeta
if (needAuth && !currentUser) {
// 未登录时重定向到登录页面
...
...
src/views/auth/LoginPage.vue
View file @
a8eee9b
...
...
@@ -297,9 +297,10 @@ const handleSubmit = async () => {
if (success) {
// 如果有重定向参数,登录成功后跳转到对应页面
const redirect = $route.query.redirect;
router.push(redirect || "/");
// router.push("/");
// 说明:redirect 是经过 URL 编码的,需要先解码再跳转
const redirect_raw = $route.query.redirect;
const redirect = redirect_raw ? decodeURIComponent(redirect_raw) : "/";
router.push(redirect);
} else {
error.value = "登录失败,请检查您的输入项";
}
...
...
Please
register
or
login
to post a comment