react+antd导航菜单,刷新后选中状态

import { withRouter } from 'react-router-dom';
export default withRouter(LayerSider);

        

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

默认情况下必须是经过路由匹配渲染的组件才存在this.props,才拥有路由参数,才能使用编程式导航的写法,执行this.props.history.push("detail")跳转到对应路由的页面

然而不是所有组件都直接与路由相连(通过路由跳转到此组件)的,当这些组件需要路由参数时,使用withRouter此组件的this.props为空,没法执行props中的history、location、match等方法。

https://blog.csdn.net/youlinaixu/article/details/92085600

你可能感兴趣的:(react)