Skip to content

Commit 71aea53

Browse files
committed
Add window.onbeforeunload
1 parent 47f7f2f commit 71aea53

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/frontend/components/App/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ class App extends BaseComponent {
7575

7676
toggleHistoryBlock(enable = !this.unblock) {
7777
if (enable) {
78+
const warningMessage = 'Are you sure you want to discard changes?';
79+
window.onbeforeunload = () => this.isSaved() ? undefined : warningMessage;
7880
this.unblock = this.props.history.block((location) => {
7981
if (location.pathname === this.props.location.pathname) return;
80-
if (!this.isSaved()) return 'Are you sure want to discard changes?';
82+
if (!this.isSaved()) return warningMessage;
8183
});
8284
} else {
85+
window.onbeforeunload = undefined;
8386
this.unblock();
8487
this.unblock = undefined;
8588
}

0 commit comments

Comments
 (0)