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
2026-01-20 10:24:53 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7fae05355b645a3c28949213967a55f5386122c7
7fae0535
1 parent
a901435b
fix(router): 修复路由守卫中未授权访问检查逻辑
处理当 to 对象缺少 matched 属性时的边界情况,确保授权检查逻辑的健壮性
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
src/router/guards.js
src/router/routes.js
src/router/guards.js
View file @
7fae053
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-
19 14:11:06
* @LastEditTime: 2026-01-
20 10:18:33
* @FilePath: /mlaj/src/router/guards.js
* @Description: 路由守卫逻辑
*/
...
...
@@ -118,7 +118,12 @@ export const checkAuth = (to) => {
return to.path.startsWith(route.path)
})
// 方式二:读取路由元信息 requiresAuth(推荐)
const needAuthByMeta = to.matched.some(record => record.meta && record.meta.requiresAuth === true)
// 注意:axios 拦截器中调用时,to 可能不是完整的 Route 对象,可能缺少 matched 属性
// 如果没有 matched 属性,则回退到仅依赖 path 的白名单匹配
const needAuthByMeta = to.matched
? to.matched.some(record => record.meta && record.meta.requiresAuth === true)
: false;
const needAuth = needAuthByList || needAuthByMeta
if (needAuth && !currentUser) {
...
...
src/router/routes.js
View file @
7fae053
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 202
5-12-31 14:33:46
* @LastEditTime: 202
6-01-20 10:23:54
* @FilePath: /mlaj/src/router/routes.js
* @Description: 路由地址映射配置
*/
...
...
@@ -289,6 +289,7 @@ export const routes = [
component
:
()
=>
import
(
'@/views/study/studyDetailPage.vue'
),
meta
:
{
title
:
'学习详情页面'
,
requiresAuth
:
true
,
}
},
{
...
...
Please
register
or
login
to post a comment