diff --git a/src/app/form.guard.ts b/src/app/form.guard.ts index bec14c4..60b62b7 100644 --- a/src/app/form.guard.ts +++ b/src/app/form.guard.ts @@ -3,11 +3,11 @@ import { HotelFormComponent } from './hotel-form/hotel-form.component'; import { HotelDetailsComponent } from './hotel-details/hotel-details.component'; export const formGuard: CanDeactivateFn = (component: HotelFormComponent | HotelDetailsComponent, currentRoute, currentState, nextState) => { - console.log(component) - if (component instanceof HotelFormComponent && component.form?.dirty) { - return confirm('You have unsaved changes. Do you really want to leave?'); - } - else if (component instanceof HotelDetailsComponent && component.hotelForm?.form?.dirty) { + const hasUnsavedChanges = + (component instanceof HotelFormComponent && component.form?.dirty) || + (component instanceof HotelDetailsComponent && component.hotelForm?.form?.dirty); + + if (hasUnsavedChanges) { return confirm('You have unsaved changes. Do you really want to leave?'); }