W3cubDocs

/Angular

mapToCanDeactivate

function

Maps an array of injectable classes with canDeactivate functions to an array of equivalent CanDeactivateFn for use in a Route definition.

See more...

mapToCanDeactivate<T = unknown>(providers: Type<{ canDeactivate: CanDeactivateFn<T>; }>[]): CanDeactivateFn<T>[]

Parameters
providers Type<{ canDeactivate: CanDeactivateFn<T>; }>[]
Returns

CanDeactivateFn<T>[]

See also

Description

Usage

@Injectable({providedIn: 'root'})
export class AdminGuard {
  canActivate() {
    return true;
  }
}

const route: Route = {
  path: 'admin',
  canActivate: mapToCanActivate([AdminGuard]),
};

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/router/mapToCanDeactivate