Guys i'm trying to make a auth guard to guard routes that someone who isnt authenticated cannot access. In my AuthService i imported Can Activate like this:
import { CanActivate, ActivatedRouteSnapshot } from '@angular/router';
I also used the implements in the export like this:
export class AuthService implements CanActivate {
And i created the canActivate mathod like this:
canActivate(route: ActivatedRouteSnapshot): boolean {
if(!this.isAuthenticated()){
this.logout();
return false;
}
return true;
}
But when i try to use it in the const routes in the app-routing.module it throws an error saying that it could not find name 'canActivate' (im removing the imports just to save some space)
canActivate: [AuthService],
children: [
{
path: 'dashboard',
loadChildren: () => import() },
{
path: '',
loadChildren: () => import() },
{
path: 'modules',
loadChildren: () => import() },
{
path: 'settings',
loadChildren: () => import() }
]
The errors i'g getting are "Cannot find name 'canActivate'" and "Cannot find name 'children'". Does someone have any idea of what could be the cause of this?
Guys i misplaced some things and that was why it was throwing an error, thanks for the comments :)