0
0
JRJose Romero
The NameGuard class implements the CanDeactivate interface, which specifies that the class can be used to determine if a component can be deactivated. The code first imports the CanDeactivate interface and then defines a method called canDeactivate. This method takes three arguments: the current route object, the current state object, and the ComponentNameComponent object.
The canDeactivate method returns an Observable that will tell you if the component can be deactivated. If the component can be deactivated, the canDeactivate method will return true. Otherwise, the canDeactivate method will return false.
Library: angular
Shortcut: angular.guard.deactivate
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanDeactivate, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
@Injectable({providedIn: 'root'})
export class NameGuard implements CanDeactivate<ComponentNameComponent> {
canDeactivate(
component: ComponentNameComponent,
currentRoute: ActivatedRouteSnapshot,
currentState: RouterStateSnapshot
): Observable<boolean>|Promise<boolean>|boolean {
return false;
}
}