diff --git a/mock/user.ts b/mock/user.ts index d2cd58e..2493864 100644 --- a/mock/user.ts +++ b/mock/user.ts @@ -114,7 +114,7 @@ const userApi = { handleCommonRes({ authority: [ '/', - '/about/u/1', + '/about/u/index', '/about/u/2', '/about/m', '/about/um', diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 530a4c4..d4c62a0 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -41,13 +41,15 @@ const handleGetOpenKeys = (currentLocation: API.MenuItem[] | []): string[] => { res.push(`${currentLocation[i].key}`); } + console.log('res', res); + + return res; }; //自定义的layout页面, 顶部导航通栏+侧边栏(菜单)布局, 可根据需要做调整 const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatch: any, location: any }> = (props) => { const [collapsed, setCollapsed] = useState(false); - const [openKeys, setOpenKeys] = useState(['']); const { pathname } = useLocation(); @@ -63,23 +65,12 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc } = props; console.log('props', props); - const [activeKey, setActiveKey] = useState('/') - - + console.log('pathname', pathname); const validMenuItem = indexValidMenuItemByPath[pathname]; - const selectedKeys = validMenuItem?.key; + // const selectedKeys = validMenuItem?.key; + const [activeKey, setActiveKey] = useState(validMenuItem?.key || '/') - useEffect( - () => { - //每次页面重新渲染都要设置openKeys - setOpenKeys( - handleGetOpenKeys( - handleGetCurrentLocation(indexValidMenuItemByPath[pathname], indexAllMenuItemById), - ), - ); - }, - [pathname, indexAllMenuItemById, indexValidMenuItemByPath], - ); + //Menu中的selectedKeys和openKeys不是一回事: //openKeys: @@ -139,9 +130,7 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc // ], // }, // ]; - console.log('consumableMenu', consumableMenu); const location = useLocation(); - console.log('location', location); // 改变panes @@ -297,16 +286,14 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc }} actionsRender={() =>