提交 71aea535 编写于 作者: J Jason Park

Add window.onbeforeunload

上级 47f7f2f6
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册