Skip to content

Commit 1fc54fb

Browse files
committed
Prevent page from closing on accidental navigation (forward, backward or page reload)
1 parent de3af7f commit 1fc54fb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: src/views/EditorView/EditorView.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import './EditorView.scss';
33
import EditorContainer from './EditorContainer/EditorContainer';
44
import {PopupWindowType} from '../../data/enums/PopupWindowType';
@@ -22,6 +22,19 @@ const EditorView: React.FC<IProps> = ({activePopupType}) => {
2222
);
2323
};
2424

25+
useEffect(() => {
26+
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
27+
event.preventDefault();
28+
event.returnValue = '';
29+
};
30+
31+
window.addEventListener('beforeunload', handleBeforeUnload);
32+
33+
return () => {
34+
window.removeEventListener('beforeunload', handleBeforeUnload);
35+
};
36+
}, []);
37+
2538
return (
2639
<div
2740
className={getClassName()}

0 commit comments

Comments
 (0)