1
我嘗試實施AUTH警衛保護我的應用程序,這是我的代碼:angular2實現AuthGuard內接口
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;
}
}
}
和錯誤消息:
[TS]班 'AuthGuard' 錯誤實現'CanActivate'接口。 類型'AuthGuard'中缺少'canActivate'屬性。
我就淨搜索,但無法找到任何有價值的信息,請幫助我,如果你有這樣的問題,遇到和解決或你有任何想法..
:)謝謝... – TyForHelpDude
駝峯!謝謝! – etlds
同樣的錯誤:) – Zub