18 lines
517 B
TypeScript
18 lines
517 B
TypeScript
// #docregion
|
|
import { Injectable } from '@angular/core';
|
|
import { CanDeactivate } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
|
|
export interface CanComponentDeactivate {
|
|
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
|
|
}
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
|
|
canDeactivate(component: CanComponentDeactivate) {
|
|
return component.canDeactivate ? component.canDeactivate() : true;
|
|
}
|
|
}
|