Angular CanActivate Guard




    Angular snippets for TypeScript

    The @Injectable() decorator allows us to inject the NameGuard class into our application. The constructor of the NameGuard class sets up the canActivate method which returns true if the user can activate the route.

    Library: angular

    Shortcut: a_guard_can_activate

    import { Injectable } from '@angular/core';
    import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
    @Injectable({providedIn: 'root'})
    export class NameGuard implements CanActivate {
      constructor() { }
      canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        return true;
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.