|
@@ -6,7 +6,19 @@ const menuStyle = { height: '100%' };
|
6
|
6
|
export default (props) => {
|
7
|
7
|
const { theme, items, location } = props;
|
8
|
8
|
|
|
9
|
+ const selectedKeys = React.useMemo(() => {
|
|
10
|
+ const parts = location.pathname.split('/').filter(Boolean);
|
|
11
|
+ const keys = parts.reduce((acc, it) => {
|
|
12
|
+ const parent = acc.pop();
|
|
13
|
+ const path = !parent ? `/${it}` : `${parent}/${it}`
|
|
14
|
+
|
|
15
|
+ return acc.concat([parent, path].filter(Boolean));
|
|
16
|
+ }, []);
|
|
17
|
+
|
|
18
|
+ return keys;
|
|
19
|
+ }, [location.pathname]);
|
|
20
|
+
|
9
|
21
|
return (
|
10
|
|
- <Menu style={menuStyle} theme={theme} items={items} selectedKeys={[location.pathname]} />
|
|
22
|
+ <Menu style={menuStyle} theme={theme} items={items} selectedKeys={selectedKeys} />
|
11
|
23
|
)
|
12
|
24
|
}
|