const [active, setActive] = useState('');
const items = [
{ key: 'product', path: '/admin/dashboard' },
{ key: 'create-product', path: '/admin/create-product' },
{ key: 'create-product-manage', path: '/admin/create-product-manager' },
{ key: 'product-manager', path: '/admin/product-manager/:id' },
{ key: 'product-managers', path: '/admin/product-managers' },
{ key: 'sale', path: '/admin/sales' },
{ key: 'analyze', path: '/admin/analyze' },
];
const onClickMenu = item => {
const clicked = items.find(_item => _item.key === item.key);
history.push(clicked.path);
};
useEffect(() => {
let path = window.location.pathname.split('/').pop();
if (path === '') {
path = 'dashboard';
}
setActive(path);
setSelectedKey(
items.find(_item => window.location.pathname.startsWith(_item.path).key)
);
}, [window.location.pathname]);
<Menu>
<Menu.Item
className="item"
key="product"
icon={<Product isActive={active === 'dashboard'} />}
onClick={() => history.push('/admin/dashboard')}
/>
<Menu.Item
className="item"
key="sale"
icon={<Sale isActive={active === 'sale'} />}
onClick={() => history.push('/admin/sale')}
/>
</Menu>