简体   繁体   English

react路由器仅替换了history.push上的最终路由

[英]react router is only replacing the final route on history.push

I am trying to redirect with react router to another page after a certain amount of time has passed. 经过一定时间后,我尝试使用react router重定向到另一个页面。

The code I have so far is: 到目前为止,我的代码是:

 submitActivity(){
        axios.post('/tiles', {
            activityDate:this.state.startDate,
            planId:this.state.planId,
            value:this.state.sliderValue
        })
            .then(res=>{
                console.log(res);
                this.modalHandleShow();
                setTimeout(function(){
                    this.goBackToTile();
                }.bind(this),3000);
            })
            .catch(err=>console.log(err));
    }

    goBackToTile(){
        this.props.history.push(`tile/${this.state.tileId}`)
    }

history is definitely being called, but the url which is currently 历史肯定被称为,但目前的网址

/addActivity/tile/2/plan/9

only gets changed to /addActivity/tile/2/plan/tile/2 仅更改为/ addActivity / tile / 2 / plan / tile / 2

while /tile/2 is correct I don't understand why the rest of the url stays in tact? 虽然/ tile / 2是正确的,但我不明白为什么其余的URL保持原样?

Make sure you include a / in the beginning of the string, or it will be used relative to your current url. 确保在字符串的开头包含一个/ ,否则它将相对于您当前的URL使用。

goBackToTile() {
    this.props.history.push(`/tile/${this.state.tileId}`)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM