Bird
0
0

Which of the following is the correct syntax to apply a canDeactivate guard to a route in Angular?

easy📝 Syntax Q12 of 15
Angular - Routing
Which of the following is the correct syntax to apply a canDeactivate guard to a route in Angular?
A{ path: 'edit', component: EditComponent, canDeactivate: [UnsavedChangesGuard] }
B{ path: 'edit', component: EditComponent, canLoad: [LoadGuard] }
C{ path: 'edit', component: EditComponent, canActivate: [AuthGuard] }
D{ path: 'edit', component: EditComponent, canActivateChild: [ChildGuard] }
Step-by-Step Solution
Solution:
  1. Step 1: Identify the guard type for leaving routes

    canDeactivate is used to check if navigation away from a route is allowed.
  2. Step 2: Match syntax with canDeactivate

    The correct syntax uses canDeactivate: [GuardName] inside the route object.
  3. Final Answer:

    { path: 'edit', component: EditComponent, canDeactivate: [UnsavedChangesGuard] } -> Option A
  4. Quick Check:

    canDeactivate syntax = canDeactivate: [Guard] [OK]
Quick Trick: Use canDeactivate: [Guard] to protect leaving a route [OK]
Common Mistakes:
MISTAKES
  • Using canActivate instead of canDeactivate for leaving routes
  • Confusing canLoad with canDeactivate
  • Missing brackets around guard name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes