All quizzesMedium
Guards & Lazy Loading
Preview — 3 of 10 questions
How do you implement a route guard in Angular 15+ standalone style?
ACreate a class implementing CanActivate and provide it with { provide: CanActivate, useClass: MyGuard }
BDecorate a method with @Guard() in the component class
CWrite a function matching CanActivateFn and add it to the route's canActivate array
DOverride the Router.navigate() method with custom logic
When would you use a CanDeactivate guard?
ATo prevent users from navigating to a protected route
BTo validate route parameters before activating a component
CTo clean up component resources before destruction
DTo prevent navigation away from a route — e.g., when a form has unsaved changes
What is the correct way to lazy-load a component in Angular 17+ standalone routing?
A{ path: 'admin', component: () => import('./admin.component') }
B{ path: 'admin', module: () => import('./admin/admin.module') }
C{ path: 'admin', component: AdminComponent, lazy: true }
D{ path: 'admin', loadComponent: () => import('./admin/admin.component').then(m => m.AdminComponent) }
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.