我是react-redux
的新手。我想做的是,当用户单击页面重新加载时,我收到一条消息that Changes that you mage may not be saved
。所以,在这里,在此之后,当我单击重新加载页面时,我想将用户重定向到主页。因此,目前还没有发生。所以我在做的是,
history.push({
pathname: '/quiz-questions',
state: {
isReload: false
}
})
On click of button, redirecting user to this page .
Now, In the component.
class FetchedQuestionComponent extends React.Component {
constructor(props) {
super(props);
console.log("props are", props);
this.onUnload = this.onUnload.bind(this);
}
onUnload(event) {
console.log("calling this", event);
event.returnValue = "Hellooww";
return "Hellooww";
}
componentDidMount() {
window.addEventListener('beforeunload', this.onUnload)
this.props.disableJob();
this.props.questionChangeModeFalse();
}
componentWillUnmount() {
window.removeEventListener('beforeunload', this.onUnload)
}
render() {
if (!this.props.criteria.Low[0].technology) {
return <Redirect to='/' />
}
//Other part rendering
}
}
现在,这很高兴,如果它来自另一个页面,它总是在主页上对其进行重定向。