Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

mapToCanActivate

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

See more...

      
      mapToCanActivate(providers: Type<{ canActivate: CanActivateFn; }>[]): CanActivateFn[]
    
Parameters
providers Type<{ canActivate: CanActivateFn; }>[]
Returns

CanActivateFn[]

See also

Description

Usage

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

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