0

I have built an angular website with a bootstrap navbar, where I use the [routerLinkActive] in order to highlight the links which indicate where the user is right now.

User is now at /basic/tab-control

The navlinks which don't route to a page, but just simply contain another dropdown, are protected from activation by adding a route guard to the route:

@Injectable({ providedIn: 'root' })
export class MyGuard implements CanActivate {
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => false;
}

const routes: Routes = [
  { path: '', redirectTo: '', pathMatch: 'full', canActivate: [MyGuard] },
  {
    path: 'carousel',
    loadChildren: () => import('./carousel/carousel.module').then((m) => m.CarouselModule),
  },
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule],
})
export class BasicRoutingModule {}

For angular 13 and up until 15 this used to work fine, however for angular 16 the guard is never triggered. Also not with the new route guard syntax.

Is this a bug? How can I fix this?

Edit: It even works for angular 13 with a lambda guard

Pieterjan
  • 2,738
  • 4
  • 28
  • 55

0 Answers0