From 71aea5352bf07b27f5b8f991b46c4aa3d0b70554 Mon Sep 17 00:00:00 2001 From: Jason Park Date: Mon, 10 Dec 2018 03:02:20 -0500 Subject: [PATCH] Add window.onbeforeunload --- src/frontend/components/App/index.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/frontend/components/App/index.jsx b/src/frontend/components/App/index.jsx index 3192bcd..fc0cb72 100644 --- a/src/frontend/components/App/index.jsx +++ b/src/frontend/components/App/index.jsx @@ -75,11 +75,14 @@ class App extends BaseComponent { toggleHistoryBlock(enable = !this.unblock) { if (enable) { + const warningMessage = 'Are you sure you want to discard changes?'; + window.onbeforeunload = () => this.isSaved() ? undefined : warningMessage; this.unblock = this.props.history.block((location) => { if (location.pathname === this.props.location.pathname) return; - if (!this.isSaved()) return 'Are you sure want to discard changes?'; + if (!this.isSaved()) return warningMessage; }); } else { + window.onbeforeunload = undefined; this.unblock(); this.unblock = undefined; } -- GitLab