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;
        }
      }

      Typescript language logoAngular Can Activate Guard

      Angular TypeScript Recipes

      This code defines a class, NameGuard, that implements the CanActivate interface. This interface defines a single method, canActivate, which returns a boolean value. This method is called by the ActivatedRouteSnapshot constructor when the NameGuard class is injected into an ActivatedRoute. The RouterStateSnapshot constructor is used to obtain the current state of the router. If the route is activated, the canActivate method returns true. If the route is not activated, the canActivate method returns false.

      Shortcut: angular.guard.can_activate

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.