【发布时间】:2020-06-15 13:53:18
【问题描述】:
我想在当前页面重新加载或刷新时重定向到上一页,
constructor(props) {
super(props);
this.onUnload = this.onUnload.bind(this);
this.onbeforeunload= this.onbeforeunload.bind(this)
this.state = {
show_answers: [],
other_data: [],
question: "",
answer: "",
id: 0,
};
}
onUnload() {
console.log("reloads")
this.context.router.push('/getanswer');
}
onbeforeunload(){
console.log("reloadsssss")
this.context.router.push('/getanswer');
}
我已经尝试了上述方法,但没有提出任何建议。
【问题讨论】:
-
刷新是指浏览器的F5吗?
-
是的,如果用户重新加载它
-
@NabeelAyub 嗯,它对工具有影响
-
那么我该如何管理呢?
-
@NabeelAyub 在重定向时传递一个 state 属性,并在特定页面上将其设置为 null。您可以在此特定组件中检查它
标签: reactjs react-router react-router-dom