|
@@ -1,7 +1,7 @@
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
-import { Layout, Menu, Breadcrumb } from 'antd'
|
|
|
+import { Layout, Menu } from 'antd'
|
|
|
import { Route } from 'react-router-dom'
|
|
|
-import { MailOutlined, MehOutlined } from '@ant-design/icons'
|
|
|
+import { MehOutlined } from '@ant-design/icons'
|
|
|
import './index.scss'
|
|
|
import '@ant-design/pro-table/dist/table.css'
|
|
|
import { routes } from '../router/config'
|
|
@@ -12,29 +12,28 @@ const { Header, Content, Sider } = Layout
|
|
|
const reallyRoutes = routes.map(item => item.children ? item.children : item).flat()
|
|
|
|
|
|
const AdminLayout: any = (props) => {
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- setCurrentKeys([props.history.location.pathname])
|
|
|
- }, [])
|
|
|
- const [currnetKeys, setCurrentKeys]: any = useState(["/admin/role"])
|
|
|
+ const [currentKeys, setCurrentKeys]: any = useState(["/admin/role"])
|
|
|
|
|
|
const switchRoute = route => {
|
|
|
props.history.push(route.path)
|
|
|
setCurrentKeys([route.path])
|
|
|
}
|
|
|
+ useEffect(() => {
|
|
|
+ setCurrentKeys([props.history.location.pathname])
|
|
|
+ }, [props.history.location.pathname])
|
|
|
|
|
|
return (
|
|
|
<Layout style={{ minHeight: '100vh' }}>
|
|
|
<Sider style={{ backgroundColor: 'white' }}>
|
|
|
- <Menu mode="inline" selectedKeys={currnetKeys}>
|
|
|
+ <Menu mode="inline" selectedKeys={currentKeys}>
|
|
|
{
|
|
|
- routes.map((route, index) => {
|
|
|
+ routes.map((route) => {
|
|
|
return (
|
|
|
route.children
|
|
|
?
|
|
|
- <Menu.SubMenu title={route.title}>
|
|
|
+ <Menu.SubMenu key={route.path} title={route.title}>
|
|
|
{
|
|
|
- route.children.filter(item => !item.hideInMenu).map((child, childIndex) =>
|
|
|
+ route.children.filter(item => !item.hideInMenu).map(child =>
|
|
|
<Menu.Item
|
|
|
key={child.path}
|
|
|
onClick={() => switchRoute(child)}
|
|
@@ -64,8 +63,7 @@ const AdminLayout: any = (props) => {
|
|
|
</Header>
|
|
|
<Content className='layout-content'>
|
|
|
{
|
|
|
- reallyRoutes.
|
|
|
- map(route =>
|
|
|
+ reallyRoutes.map(route =>
|
|
|
<Route
|
|
|
exact
|
|
|
path={route.path}
|