I am implementing the router guard with canDeactivate method. It does not work if I return a async Observable.
The following steps that I did.
Created guard
@Injectable()
export class DeactivateGuardService implements CanDeactivate<CanComponentDeactivate> {
canDeactivate(component: CanComponentDeactivate) {
return component.canDeactivate() || window.confirm('Are you sure?');
}
}
export interface CanComponentDeactivate {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}
implemented the method in component.ts
canDeactivate(): Observable<boolean> | boolean{
return of(false);
// return false;
}
It is working fine, If I return false but It is not working if I return of(false).
Please suggest.