admin管理员组文章数量:1394062
im starting a new angular
project, but getting the following error:
ERROR in src/app/app-routing.module.ts(11,5): error TS2740: Type 'typeof LoginGuard' is missing the following properties from type 'any[]': pop, push, concat, join, and 25 more.
what does typeof
loginGuard acually mean, and what do I need to do to make it work as it's intended to?
Here is my route file:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LoginComponent } from "./login/loginponent";
import { LoginlandingComponent} from "./loginlanding/loginlandingponent";
import { LoginGuard} from "./login.guard";
const routes: Routes = [
{ path: 'login', ponent: LoginComponent },
{
path: '',
canActivateChild: LoginGuard,
children: [
{
path: 'home',
ponent: LoginlandingComponent
}
]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Here is my guard file:
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { CanActivate, Router, Route } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class LoginGuard implements CanActivate {
constructor(private _router: Router) {
}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
if (false) {
console.log("its true");
return true;
}
console.log("redirecting");
// navigate to login page
this._router.navigate(['/login']);
return false;
}
}
im starting a new angular
project, but getting the following error:
ERROR in src/app/app-routing.module.ts(11,5): error TS2740: Type 'typeof LoginGuard' is missing the following properties from type 'any[]': pop, push, concat, join, and 25 more.
what does typeof
loginGuard acually mean, and what do I need to do to make it work as it's intended to?
Here is my route file:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LoginComponent } from "./login/login.ponent";
import { LoginlandingComponent} from "./loginlanding/loginlanding.ponent";
import { LoginGuard} from "./login.guard";
const routes: Routes = [
{ path: 'login', ponent: LoginComponent },
{
path: '',
canActivateChild: LoginGuard,
children: [
{
path: 'home',
ponent: LoginlandingComponent
}
]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Here is my guard file:
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { CanActivate, Router, Route } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class LoginGuard implements CanActivate {
constructor(private _router: Router) {
}
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
if (false) {
console.log("its true");
return true;
}
console.log("redirecting");
// navigate to login page
this._router.navigate(['/login']);
return false;
}
}
Share
Improve this question
edited Mar 7, 2019 at 10:01
Lloyd
1,12911 silver badges32 bronze badges
asked Mar 7, 2019 at 9:54
mariamaria
1595 gold badges24 silver badges62 bronze badges
1 Answer
Reset to default 11canActivateChid
should be an array value.
Change the route definition to:
{
path: '',
canActivateChild: [LoginGuard],
children: [
{
path: 'home',
ponent: LoginlandingComponent
}
]
}
Note also that you are implementing the wrong interface. If you want to use that guard for child routes, you need to implement CanActivateChild
本文标签: javascriptangular typeof guard error while compilingStack Overflow
版权声明:本文标题:javascript - angular typeof guard error while compiling - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744586874a2614248.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论