Prevents accidental page navigation when there are unsaved changes.
Sets a beforeunload event handler that shows the browser's native
confirmation dialog when enabled is true. Does NOT integrate with
the Angular Router - for route guard protection, use canDeactivateWhenClean().