react-router使用history.push路由跳轉(zhuǎn)出錯問題路由頁面http://localhost:8888/detail/5aae1cc8f5dfc27d7ad98909路由形式<Route path="/detail/:id" component = {TopicDetail} key = "detail" /><Route path="/user/login" component = {UserLogin} key = 'login' />組件TopicDetail部分代碼class TopicDetail extends React.Component{ static contextTypes = { router:PropTypes.object, } constructor(props){ super(props) this.goToLogin = this.goToLogin.bind(this) } /*-------登入并回復(fù)-------*/ goToLogin() { this.context.router.history.push('user/login') } render() { return ( <div> <section className={classes.notLoginButton}> <Button raised color="inherit" onClick={this.goToLogin}> 登入并回復(fù) </Button> </section> </div> ) }}問題:單擊按鈕調(diào)用 this.context.router.history.push('user/login'),為什么路由從http://localhost:8888/detail/5aae1cc8f5dfc27d7ad98909跳轉(zhuǎn)到http://localhost:8888/detail/user/login而不是http://localhost:8888/user/login
react-router使用history.push路由跳轉(zhuǎn)出錯
忽然笑
2019-03-21 22:19:07