I want to build a Web Application which has a form
that it's shared in multiple tabs. The functionality I want to implement is to prevent the user from reloading the page when the form
is dirty
. I tried CanDeactivate Guard, but it's useful only when the user navigates away. So, I tried this implementation like this:
@HostListener('window:beforeunload', ['$event']) onBeforeUnload(event) {
if (this.parentForm.dirty) {
this.parentForm.form.markAsPristine();
this.parentForm.form.markAsUntouched();
return false;
}
}
With this in place, I managed to prevent the user to reload, but the browser message is ugly:
Is there another way to accomplish the functionality I want with a more beautiful way?