React 报错TypeError: Cannot read property 'push' of undefined
侧边栏壁纸
  • 累计撰写 635 篇文章
  • 累计收到 0 条评论

React 报错TypeError: Cannot read property 'push' of undefined

加速器之家
2024-08-22 / 0 评论 / 3 阅读 / 正在检测是否收录...

TypeError: Cannot read property 'push' of undefined

onClick

F:/study/react/react-admin/src/compoments/Frame/Index.js:44

41 | {routes.map(routes=>{

42 | return (

43 | <Menu.Item key={routes.path}

> 44 | onClick={p=>props.history.push(p.key)} >

| ^ 45 | <IconFont type={routes.icon} />&nbsp;

46 | {routes.title}

47 | </Menu.Item>

View compiled

出现这个问题是因为我们没有引入withRouter

我们引入即可

import { withRouter } from 'react-router-dom'
export default withRouter(Index)
0

评论

博主关闭了当前页面的评论