监听浏览器刷新操作
场景:
用户点击浏览器刷新按钮时,清除state缓存
思路:
通过 监听 beforeunload 事件
方案:
React.useEffect(() => {
// 初始化
const handleInit = () => {
history.replace({...history.location, state: { ...history.location.state, propertyId: null, propertyName: null, propertyCode: null }});
ds.queryDataSet.reset();
};
window.addEventListener('beforeunload', handleInit);
return () => {
window.removeEventListener('beforeunload', handleInit);
};
}, []);
.

浙公网安备 33010602011771号