1,使用this.context.router.history.push(’/orderDetail’)
代码如下:
import PropTypes from "prop-types";
class List extends Component{
static contextTypes = {
router: PropTypes.object
}
constructor(props,context) {
super(props,context);
this.state = {};
}
handleItemClick(){//点击事件
this.context.router.history.push('/orderDetail')
}
2,官方推荐:
import {withRouter} from "react-router-dom";
class List extends Component{
constructor(props) {
super(props);
this.state = {};
}
handleItemClick(){//点击事件
this.props.history.push("/orderDetail");
}