angular2实现了AuthGuard中的接口

TyF*_*ude 1 angular

我尝试为我的应用程序实现auth guard保护,这是我的代码:

import {Injectable} from '@angular/core'
import {Router, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'
import {CanActivate} from '@angular/router'
import {Auth} from './services/auth.service'

@Injectable()
export class AuthGuard implements CanActivate {

    constructor(private auth:Auth, private router:Router){

    }
    CanActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot){
        if(this.auth.authenticated()){
        console.log("AUTH GUARD LET GO");
        return true;
        }
        else{
            console.log("BLOCKED BY AUTH GUARD");
            this.router.navigate(['/']);
            return false;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和错误消息:

[ts] Class'AuthGuard'错误地实现了接口'CanActivate'.'AuthGuard'类型中缺少属性'canActivate'.

我在网上搜索,但无法找到任何有价值的信息,请帮助我,如果你遇到这种问题并解决或任何想法你...

LLa*_*Lai 8

错误是说您的应用程序找不到正确的功能可用于激活.canActivate函数名是camelCase,试试吧

canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot){
    //logic
}
Run Code Online (Sandbox Code Playgroud)