路由修复

This commit is contained in:
‘Liammcl’
2025-01-15 00:59:16 +08:00
parent e4aa910d4e
commit 027a8e5493
3 changed files with 45 additions and 6 deletions

View File

@@ -14,13 +14,27 @@ const Sidebar = ({ collapsed }) => {
const { isDarkMode } = useTheme();
const { user } = useAuth();
const getSelectedKeys = useMemo(() => {
const pathname = location.pathname.substring(1);
const pathParts = pathname.split('/');
let key = '';
if (pathParts.length >= 2) {
const baseKey = `${pathParts[0]}/${pathParts[1]}`;
key = pathname.includes('/') ? baseKey : pathname;
} else {
key = pathname;
}
return [key];
}, [location.pathname]);
const menuClient = useMemo(() => {
if (!user?.id||user.menukeys?.length===0) return [];
if (!user?.id || user.menukeys?.length === 0) return [];
return getMenuItems(user?.menukeys || []);
}, [user]);
useEffect(()=>{
console.log(menuClient,'menuClient');
},[menuClient])
const defaultOpenKeys = useMemo(() => {
const pathSegments = location.pathname.split("/").filter(Boolean);
return pathSegments.reduce((acc, _, index) => {
@@ -48,7 +62,7 @@ useEffect(()=>{
<Menu
theme={isDarkMode ? "dark" : "light"}
mode="inline"
selectedKeys={[location.pathname]}
selectedKeys={getSelectedKeys}
defaultOpenKeys={defaultOpenKeys}
items={menuClient}
onClick={handleMenuClick}