使用React.js,我如何检查整个页面是否被重新加载?
if (window.performance) {
console.info("window.performance works fine on this browser");
}
console.info(performance.navigation.type);
if (performance.navigation.type == performance.navigation.TYPE_RELOAD) {
console.info("This page is reloaded");
} else {
console.info("This page is not reloaded");
}
上面的代码没有帮助,每次我更改组件或调用同一页面上的任何api时都会触发。
try this
onUnload(event) {
alert('page Refreshed')
}
componentDidMount() {
window.onbeforeunload = function() {
this.onUnload();
return "";
}.bind(this);
}