Bird
0
0

Which Angular route guard is best suited to block navigation away from a component when there are unsaved form changes?

easy🧠 Conceptual Q2 of 15
Angular - Routing
Which Angular route guard is best suited to block navigation away from a component when there are unsaved form changes?
A<code>canActivate</code>
B<code>canDeactivate</code>
C<code>resolve</code>
D<code>canLoad</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify guard purpose

    canDeactivate is designed to prevent leaving a route under certain conditions.
  2. Step 2: Exclude other guards

    canActivate controls entering routes, resolve pre-fetches data, and canLoad controls lazy loading.
  3. Final Answer:

    canDeactivate -> Option B
  4. Quick Check:

    Unsaved changes require canDeactivate guard [OK]
Quick Trick: Use canDeactivate to block leaving with unsaved changes [OK]
Common Mistakes:
MISTAKES
  • Using canActivate to prevent leaving a route
  • Confusing resolve with navigation guards
  • Thinking canLoad handles form state

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes