diff --git a/src/SiderMenu/BaseMenu.tsx b/src/SiderMenu/BaseMenu.tsx index 803a483d..bd33085f 100644 --- a/src/SiderMenu/BaseMenu.tsx +++ b/src/SiderMenu/BaseMenu.tsx @@ -310,7 +310,6 @@ const BaseMenu: React.FC = (props) => { ); useEffect(() => { - setPostMenuData(menuData); if (menu.defaultOpenAll || propsOpenKeys === false || flatMenuKeys.length) { return; } @@ -367,7 +366,11 @@ const BaseMenu: React.FC = (props) => { useEffect(() => { if (splitMenus && openKeys) { - const key = [...openKeys].shift(); + const keys = getSelectedMenuKeys( + location.pathname || '/', + menuData || [], + ); + const [key] = keys; if (key) { const postData = menuData?.find((item) => item.key === key)?.children || []; @@ -375,10 +378,8 @@ const BaseMenu: React.FC = (props) => { return; } } - if (!splitMenus) { - setPostMenuData(menuData); - } - }, [(openKeys || []).join('-'), splitMenus]); + setPostMenuData(menuData); + }, [pathname, splitMenus, flatMenuKeys.join('-')]); // 这次 openKeys === false 的时候的情况,这种情况下帮用户选中一次 // 第二次以后不再关系,所以用了 defaultOpenKeys diff --git a/tests/__tests__/__snapshots__/index.test.tsx.snap b/tests/__tests__/__snapshots__/index.test.tsx.snap index a7f36384..95d3bb12 100644 --- a/tests/__tests__/__snapshots__/index.test.tsx.snap +++ b/tests/__tests__/__snapshots__/index.test.tsx.snap @@ -93,11 +93,7 @@ exports[`BasicLayout 🥩 base use 1`] = `
-
-
+ /> @@ -197,11 +193,7 @@ exports[`BasicLayout 🥩 contentStyle should change dom 1`] = `
-
-
+ /> @@ -300,11 +292,7 @@ exports[`BasicLayout 🥩 menuDataRender change date 1`] = `
-
-
+ /> @@ -423,11 +411,7 @@ exports[`BasicLayout 🥩 menuDataRender change date 2`] = `
-
-
+ /> @@ -528,31 +512,27 @@ exports[`BasicLayout 🥩 support loading 1`] = ` class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header" >
-
- - - - - - -
+ + + + +
@@ -707,11 +687,7 @@ exports[`BasicLayout 🥩 support menuDataRender 1`] = `
-
-
+ /> diff --git a/tests/__tests__/__snapshots__/pageHeaderWarp.test.tsx.snap b/tests/__tests__/__snapshots__/pageHeaderWarp.test.tsx.snap index 7d86a3ae..4b6deaf5 100644 --- a/tests/__tests__/__snapshots__/pageHeaderWarp.test.tsx.snap +++ b/tests/__tests__/__snapshots__/pageHeaderWarp.test.tsx.snap @@ -115,40 +115,36 @@ exports[`BasicLayout base use 1`] = ` class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header" >
-
- - welcome - -
+ welcome +
+
+
-
-
+ class="ant-pro-grid-content-children" + />
@@ -272,61 +268,57 @@ exports[`BasicLayout content is text 1`] = ` class="ant-layout-content ant-pro-basicLayout-content ant-pro-basicLayout-has-header" >
-
- - welcome - -
+ welcome +
+
+
-
- just so so -
+ just so so
+
+
-
-
+ class="ant-pro-grid-content-children" + />