import { Menu } from "antd"; import { useNavigate, useLocation } from "react-router-dom"; export default function NavigationMenu() { const navigate = useNavigate(); const location = useLocation(); console.log(location.pathname); // 导航菜单项配置 const menuItems = [ { key: 'staff', label: '人员总览', path: '/' }, // 将path改为根路径 { key: 'plan', label: '培训计划', path: '/plan' }, { key: 'day', label: '每日填报', path: '/daily' }, { key: 'exam', label: '考核成绩', path: '/exam' }, ]; return ( <> location.pathname.startsWith(item.path))?.key, ]} > {menuItems.map((item) => ( navigate(item.path)} >
{item.label}
))}
); }