javascript - 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.
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
while /tile/2 is correct I don't understand why the rest of the url stays in tact?
解决方案
确保/
在字符串的开头包含 a,否则它将相对于您当前的 url 使用。
goBackToTile() {
this.props.history.push(`/tile/${this.state.tileId}`)
}
推荐阅读
- c - 打印指针时出现分段错误
- windows - 在 Windows 中使用 CURL 发送文件
- python - 将鼠标悬停在图例上将隐藏除相应行之外的所有行
- php - Get all products except that already had discount?
- swift - 如何在 Swift 5 中点击关闭 AVPlayer?
- python-3.x - 有没有办法从 python 3.x 中的测试脚本隐藏登录凭据
- python - 如何使图像看起来更灰
- android - Android - 在启动动画期间无法播放音频
- r - DeMAND包中可用的指数估计方法,在R中
- ios - SwiftUI 列表中所有行的高度相同