11
react-router(v4)如何返回?
试图弄清楚如何返回上一页。我在用[react-router-v4][1] 这是我在第一个登录页面中配置的代码: <Router> <div> <Link to="/"><div className="routerStyle"><Glyphicon glyph="home" /></div></Link> <Route exact path="/" component={Page1}/> <Route path="/Page2" component={Page2}/> <Route path="/Page3" component={Page3}/> </div> </Router> 为了转发到后续页面,我只需执行以下操作: this.props.history.push('/Page2'); 但是,如何返回上一页?尝试了以下一些事情,但没有运气:1。this.props.history.goBack(); 给出错误: TypeError:null不是对象(评估“ this.props”) this.context.router.goBack(); 给出错误: TypeError:null不是对象(评估“ this.context”) this.props.history.push('/'); 给出错误: TypeError:null不是对象(评估“ this.props”) Page1在下面发布代码: import React, {Component} from 'react'; import {Button} from 'react-bootstrap'; class Page1 extends Component { …