路由修复
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user