React-router routing jump error using history.push

< H2 > react-router routing jump error using history.push < / H2 >
  • routing page http://localhost:8888/detail/5aae1cc8f5dfc27d7ad98909
  • Route form
<Route path="/detail/:id" component = {TopicDetail} key = "detail" />
<Route path="/user/login" component = {UserLogin} key = "login" />
  • component TopicDetail partial code
class TopicDetail extends React.Component{
    static contextTypes = {
        router:PropTypes.object,
    }
    constructor(props){
        super(props)
        this.goToLogin = this.goToLogin.bind(this)
    }
    /*--------------*/
    goToLogin() {
        this.context.router.history.push("user/login")
    }

    render() {
        return (
            <div>
                <section className={classes.notLoginButton}>
                    <Button raised color="inherit" onClick={this.goToLogin}>
                                     
                    </Button>
                </section>
            </div>
        )
    }
}
  • question: Click the button to call this.context.router.history.push ("user/login"). Why does the route jump from http://localhost:8888/detail/5aae1cc8f5dfc27d7ad98909 to http://localhost:8888/detail/user/login instead of http://localhost:8888/user/login?
Mar.02,2021

it's best to give the code Demo, so that it doesn't solve


see if there's anything wrong with the path, and add a "/". / "give it a try.


<Switch>
 <Router />
 <Router />
</Switch>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2292a-2a36d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2292a-2a36d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?