hookehuyr

fix(router): 修复路由守卫中未授权访问检查逻辑

处理当 to 对象缺少 matched 属性时的边界情况,确保授权检查逻辑的健壮性
/*
* @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) {
......
/*
* @Date: 2025-03-20 20:36:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-12-31 14:33:46
* @LastEditTime: 2026-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,
}
},
{
......