我正在使用React js。我需要检测page refresh. 当用户点击刷新图标或按 F5 时,我需要找出事件。
我通过使用 javascript 函数尝试了stackoverflow 帖子
我使用 javascript 函数beforeunload仍然没有运气。
onUnload(event) {
alert('page Refreshed')
}
componentDidMount() {
window.addEventListener("beforeunload", this.onUnload)
}
componentWillUnmount() {
window.removeEventListener("beforeunload", this.onUnload)
}
这里我有关于stackblitz 的完整代码