2019-12-04 19:24:40 +01:00
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
import {Injectable} from '@angular/core';
|
2023-08-01 13:29:27 +02:00
|
|
|
|
2019-12-04 19:24:40 +01:00
|
|
|
|
|
|
|
export interface IDeactivateComponent {
|
|
|
|
canExit: () => Observable<boolean> | Promise<boolean> | boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
2023-08-01 13:29:27 +02:00
|
|
|
export class CanExitGuard {
|
2019-12-04 19:24:40 +01:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
canDeactivate(component: IDeactivateComponent): Observable<boolean> | Promise<boolean> | boolean {
|
|
|
|
|
|
|
|
return component.canExit ? component.canExit() : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|