/** * 角色路由守卫 — 拦截非授权角色访问受保护路由 * 用法: } /> */ import { Navigate } from 'react-router-dom' import useAuthStore from '../../stores/authStore' function RoleGuard({ children, roles }) { const { user } = useAuthStore() if (!user) return null // AuthGuard 已处理未登录跳转 if (!roles.includes(user.role)) { return } return children } export default RoleGuard