A problem has arisen while using canActivateChild
or canActivate
in the child route. Despite working fine previously, an error is now being thrown:
ERROR in src/app/app-routing.module.ts(8,7): error TS2322: Type '({ path: string; redirectTo: string; pathMatch: string; } | { path: string; component: typeof Log...' is not assignable to type 'Route[]'.
Type '{ path: string; redirectTo: string; pathMatch: string; } | { path: string; component: typeof Logi...' is not assignable to type 'Route'.
Type '{ path: string; component: typeof MainContentComponent; canActivateChild: typeof PlayVidAuthGuard...' is not assignable to type 'Route'.
Types of property 'canActivateChild' are incompatible.
Type 'typeof PlayVidAuthGuardService' is not assignable to type 'any[]'.
Property 'includes' is missing in type 'typeof PlayVidAuthGuardService'.
The routing module causing this issue looks like this:
const appRoutes: Routes = [
{ path: "", redirectTo: "login", pathMatch: "full" },
{ path: "login", component: LoginComponent },
{
path: "home",
component: MainContentComponent,
canActivateChild: PlayVidAuthGuardService,
children: [
{
path: "",
component: PlayVideoComponent
}
]
}
];
Removing the canActivateChild
attribute resolves the error.
export class PlayVidAuthGuardService implements CanActivate {
constructor() {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return true;
}
}
Even adding canActivate
to the child route results in the same error message. How can this be fixed? Thank you!