Monday, 26 April 2021

angular active gaurd example

 ng g guard <name>

give u 4 different options from that select one

import { Injectable } from '@angular/core';
import { CanActivate, CanActivateChild, CanDeactivate, CanLoad,  Route, UrlSegment, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree }  from '@angular/router';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class GuardNameGuard implements CanActivate, CanActivateChild,  CanDeactivate<unknown>, CanLoad {
  canActivate(
    nextActivatedRouteSnapshot,
    stateRouterStateSnapshot)Observable<boolean | UrlTree>  | Promise<boolean | UrlTree> | boolean | UrlTree {
    return true;
  }
  canActivateChild(
    nextActivatedRouteSnapshot,
    stateRouterStateSnapshot)Observable<boolean | UrlTree>  | Promise<boolean  | UrlTree> | boolean | UrlTree {
    return true;
  }
  canDeactivate(
    componentunknown,
    currentRouteActivatedRouteSnapshot,
    currentStateRouterStateSnapshot,
    nextState?: RouterStateSnapshot)Observable<boolean | UrlTree>  | Promise<boolean | UrlTree> | boolean | UrlTree {
    return true;
  }
  canLoad(
    routeRoute,
    segmentsUrlSegment[])Observable<boolean> | Promise<boolean>  | boolean {
    return true;
  }
}


here i selected all so generated details study needed on this

No comments:

Post a Comment

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...