【发布时间】:2018-11-07 19:46:41
【问题描述】:
我正在使用 react-router v.4,我想执行一些返回功能。
我当前的代码如下所示:
<HashRouter>
<Switch>
<Route exact path='/' component={Main}/>
<Route path='/secondview' component={SecondView}/>
<Route path='/traineeships' render={()=>(<Traineeship rootState={this.state} setRootState={this.setState.bind(this)} />)}/>
<Route path='/information-filter' render={()=>(<InformationFilter rootState={this.state} setRootState={this.setState.bind(this)} />)}/>
<Route path='/find-work' render={()=>(<FindWork rootState={this.state} setRootState={this.setState.bind(this)} />)}/>
<Route path='/information-job' render={()=>(<InformationJob rootState={this.state} setRootState={this.setState.bind(this)} />)}/>
<Redirect from='*' to='/' />
</Switch>
我在其他组件上尝试了几个选项,例如 this.props.history.go(-1),但我遇到了未定义的错误。
有谁知道在我的情况下如何执行返回功能?
【问题讨论】:
-
@VicJordan 我得到 Uncaught TypeError: Cannot read property 'goBack' of undefined 当我和那个重复问题的答案一样时!
-
您的页面是否使用
withRouter? github.com/ReactTraining/react-router/blob/master/packages/… -
请提供minimal reproducible example 以获得更好的答案。
标签: javascript reactjs react-native react-router-v4