Guard related problem
export const canActiveChildGuard: CanActivateChildFn = (childRoute, state) => {
const router = inject(Router);
// const router = new Router;
console.log("child");
const token = localStorage.getItem('token');
if (token) {
return true;
}
else {
router.navigate(['Home'])
return false;
}
};
angular.module.ts file
{
path: 'Courses',
component: CourseComponent,
canActivateChild: [canActiveChildGuard],
children: [
{ path: 'Course/:id', component: OneCourseComponent }
]
},
I try to prevent the execution if token is not there in the local storage. My canActiveChild guard would not called i don't know how.
I want if token is there in the local storage then and then only user will access child route otherwise not.
I'm facing this problem in angular16 version.`