Angular Can Activate Guard Child



    Jose Romero

    Angular TypeScript Recipes

    This class provides an "Injectable" so that you can add it as a dependency in your app. Next, the class contains a constructor that sets up the state and a canActivateChild() method which returns a boolean value telling the router whether the child can be activated. The router will only allow the child to be activated if the canActivateChild() method returns true.

    Library: angular

    Shortcut: angular.guard.can_activate.child

    import { Injectable } from '@angular/core';
    import { ActivatedRouteSnapshot, CanActivateChild, RouterStateSnapshot } from '@angular/router';
    @Injectable({providedIn: 'root'})
    export class NameGuard implements CanActivateChild {
      constructor() { }
      canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        return true;
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.