Angular5 canactivate guard :Types of property 'canActivate' are incompatible

iam batman

I am trying to implement simple canActivate in my Auth service

import {CanActivate,ActivatedRouteSnapshot} from '@angular/router';
export class Auth implements CanActivate{
    canActivate(
        next: ActivatedRouteSnapshot,
        state: ActivatedRouteSnapshot
      ): Observable<boolean> {

            return Observable.of(true);
      }
}

got this error

ERROR in src/app/modules/user/auth.ts(13,14): error TS2420: Class 'Auth' incorrectly implements interface 'CanActivate'. Types of property 'canActivate' are incompatible. Type '(next: ActivatedRouteSnapshot, state: ActivatedRouteSnapshot) => Observable' is not assignable to type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => boolean | Promise | Obser...'. Types of parameters 'state' and 'state' are incompatible. Type 'RouterStateSnapshot' is not assignable to type 'ActivatedRouteSnapshot'. Types of property 'url' are incompatible. Type 'string' is not assignable to type 'UrlSegment[]'.

aspnet82

I think the problem is the declaration of state: should be RouterStateSnapshot

interface CanActivate { 
   canActivate(route: ActivatedRouteSnapshot, 
               state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular2 CanActivate guard not working

Angular canActivate Security

Return observable inside observable in canactivate guard of Angular 4

Accessing component of the ActivatedRoute in the canActivate Guard

Angular(5) - lazy loading and canActivate guard - StaticInjectorError

Get target route URL in CanActivate guard Lazy load modules Angular

Angular Route Guard CanActivate stops routing

Angular CanActivate guard - createUrlTree relative navigation

Angular CanActivate With Login Dialog

Angular canActivate Guard with API

How to redirect from parent route to child route in Angular canActivate guard?

Read cookie in CanActivate route guard in Angular

Angular 9 - Guard: canActivate wait until specific condition is met

Return condition always is false into subscribe Angular CanActivate Guard

How to check asynchronously if user is authenticated in router canActivate guard in angular 2?

Angular2: canActivate

Angular 2 canActivate async

error in canActivate guard method

Angular 2 Route Guard CanActivate based on Firebase User Role

Angular 2 router canActivate Auth Guard

Angular canactivate not fire

Angular guard canActivate method dont work with Observable<boolean>

Using defaultIfEmpty() still not emitting in Angular canActivate guard

Angular AuthGuard canActivate

Angular Router route guard CanActivate always returns false

Angular How to implement CanActivate guard with HTTP Get call

rxjs observable unsubscribe in CanActivate Guard

Angular CanActivate Guard

Authorization Issue with Angular Auth Guard canActivate method

TOP Ranking

HotTag

Archive