美文网首页
react中antd刷新页面及后退时菜单栏高亮问题

react中antd刷新页面及后退时菜单栏高亮问题

作者: jia林 | 来源:发表于2019-05-05 14:02 被阅读0次

左侧菜单刷新无法高亮用 withRouter,设置selectedKeys属性,

  • withRouter作用:把不是通过路由切换过来的组件中,将react-router 的 history、location、match 三个对象传入props对象上

1、引用import { withRouter} from "react-router-dom",用withRouter包裹返回的属性值history:
export default withRouter(SideNav),
2、Menu的selectedKeys赋值:
selectedKeys={[this.props.history.location.pathname]}

image.png

相关文章

网友评论

      本文标题:react中antd刷新页面及后退时菜单栏高亮问题

      本文链接:https://www.haomeiwen.com/subject/vjncoqtx.html