TypeError: Cannot read properties of undefined (reading 'push')
今天在写react的后台管理系统中遇到了这个问题,目的是点击不同的菜单列表展示不同的路由,出现错误的原代码如下:
const Admin = ({history}) => {
const [collapsed, setCollapsed] = useState(false);
const dispatch = useDispatch()
const loginOutConfirm = () => {
confirm({
title: '真的要退出吗?',
icon: <ExclamationCircleOutlined />,
content: '本网站不会保存你的操作,真的要退出吗?',
onOk() {
dispatch(loginOutAction())
},
onCancel() {
console.log('Cancel');
},
});
};
return (
<AdminContainer>
<Layout style={
{height:'100%' }}>
<Sider trigger={null} collapsible collapsed={collapsed}>
<div >
<img className="logo" src="https://t7.baidu.com/it/u=3571871208,2635260997&fm=193&f=GIF" alt="" />
</div>
<Menu
theme="dark"
mode="inline"
defaultSelectedKeys={[]}
defaultOpenKeys={['2']}
onClick={({key}) =>{
history.push(key)
console.log(key)
}}
items={[
{
key: '/admin/main',
icon: <UserOutlined />,
label: '后台首页',
},
{
key: '2',
icon: <VideoCameraOutlined />,