Bird
0
0

How can you combine canActivate and canDeactivate guards on the same route to protect entry and exit?

hard🚀 Application Q9 of 15
Angular - Routing
How can you combine canActivate and canDeactivate guards on the same route to protect entry and exit?
AChain guards inside a single canActivate array
BAdd both <code>canActivate</code> and <code>canDeactivate</code> arrays in the route config
CUse only canActivate; canDeactivate is ignored if canActivate exists
DUse canLoad instead of canDeactivate for exit protection
Step-by-Step Solution
Solution:
  1. Step 1: Understand guard usage in route config

    Angular allows multiple guard types on the same route by specifying separate arrays.
  2. Step 2: Apply both guards correctly

    Use canActivate: [...] and canDeactivate: [...] separately in the route definition.
  3. Final Answer:

    Add both canActivate and canDeactivate arrays in the route config -> Option B
  4. Quick Check:

    Separate arrays for canActivate and canDeactivate [OK]
Quick Trick: Use separate arrays for canActivate and canDeactivate guards [OK]
Common Mistakes:
MISTAKES
  • Trying to combine guards in one array
  • Ignoring canDeactivate when canActivate exists
  • Using canLoad for exit guard

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes