forked from wangziqi/gongxue-base
功能:支持侧边栏多项同时展开
This commit is contained in:
@@ -160,14 +160,13 @@ const MainLayout: React.FC = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (location.pathname !== prevPathname.current) {
|
if (location.pathname !== prevPathname.current) {
|
||||||
prevPathname.current = location.pathname;
|
prevPathname.current = location.pathname;
|
||||||
setOpenKeys(findOpenKeys(menuItems, location.pathname));
|
const routeOpenKeys = findOpenKeys(menuItems, location.pathname);
|
||||||
|
setOpenKeys((currentKeys) => [...new Set([...currentKeys, ...routeOpenKeys])]);
|
||||||
}
|
}
|
||||||
}, [location.pathname, menuItems]);
|
}, [location.pathname, menuItems]);
|
||||||
|
|
||||||
const handleOpenChange = useCallback((keys: string[]) => {
|
const handleOpenChange = useCallback((keys: string[]) => {
|
||||||
// 只保留最新打开的一个子菜单
|
setOpenKeys(keys);
|
||||||
const latestKey = keys[keys.length - 1];
|
|
||||||
setOpenKeys(latestKey ? [latestKey] : []);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const transformToMenuItems = (items: AppMenuItem[]): any[] => {
|
const transformToMenuItems = (items: AppMenuItem[]): any[] => {
|
||||||
|
|||||||
Reference in New Issue
Block a user