Adding the canActivate Route Guard to the Router Module
Learn how the canActivate Route Guard works in Angular.
What is the canActivate
route guard?
The canActivate
guard is a default route guard interface provided by Angular. It checks if a user can navigate a specific route or helps prevent access to a particular route. The canActivate
guard usually returns a boolean value and an
Integrating the canActivate
route guard
To integrate the canActivate
guard into our project, we need to take the following steps explained below:
Step 1: Creating the guard
To create the guard, we need to run the command below at the root of our Angular application:
ng generate guard auth/auth
...