In this lecture, we will have a look at Angular Route Guards. The Angular supports several route guards like CanActivate, CanDeactivate, Resolve, CanLoad, and CanActivateChild. These guards help us to secure the route or to perform some actions before navigating into a route or leaving the route.
We use the Angular Guards to control, whether the user can navigate to or away from the current route.
We looked at how to configure our routes and navigate to the different parts of our application using Angular Router. Allowing the user to navigate to all parts of the application is not a good idea. We need to restrict the user until the user performs specific actions like login. Angular provides the Route Guards for this same purpose.
One of the common scenario, where we use Route guards is authentication. We want our App to stop the unauthorized user from accessing the protected route. We can achieve this by using a route guard in Angular.
Uses of Angular Route Guards
- To Confirm the navigational operation
- Asking whether to save before moving away from a view
- Allow access to certain parts of the application to specific users
- Validating the route parameters before navigating to the route
- Fetching some data before you display the component.
The Angular Router supports Five different guards, which you can use to protect the route
- CanActivate
- CanDeactivate
- Resolve
- CanLoad
- CanActivateChild
DOWNLOAD SECTION SOURCE CODE HERE: drive.google.c...
26 авг 2024