使用redux后打印props发现没有history
解决方案:
引入withRouter方法:
import { withRouter } from ‘react-router-dom’;
导出组件时调用
export default connect(mapStateToProps,mapDispatchToProps)(withRouter(Sidebar));
之后Sidebar组件中就可以使用this.props.history.push来跳转了
使用redux后打印props发现没有history
解决方案:
引入withRouter方法:
import { withRouter } from ‘react-router-dom’;
导出组件时调用
export default connect(mapStateToProps,mapDispatchToProps)(withRouter(Sidebar));
之后Sidebar组件中就可以使用this.props.history.push来跳转了