22 lines
553 B
TypeScript
22 lines
553 B
TypeScript
import {Observable} from 'rxjs';
|
|
import {Injectable} from '@angular/core';
|
|
import {CanDeactivate} from '@angular/router';
|
|
|
|
export interface IDeactivateComponent {
|
|
canExit: () => Observable<boolean> | Promise<boolean> | boolean;
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class CanExitGuard implements CanDeactivate<IDeactivateComponent> {
|
|
|
|
constructor() {
|
|
}
|
|
|
|
canDeactivate(component: IDeactivateComponent): Observable<boolean> | Promise<boolean> | boolean {
|
|
|
|
return component.canExit ? component.canExit() : true;
|
|
}
|
|
|
|
} |