Guard are a really useful feature in Angular for protecting routes. They provide the security feature used to restrict resources in our application so that the user is not able to consume a resource without proper permission.
There are different guard types in Angular:
- CanActivate: This is used to decide whether the route can be activated
- CanActivateChild: This is used to decide whether the child route can be activated
- CanDeactivate: This is used to decide whether the route can be deactivated
- CanLoad: This is used to decide whether the module can be loaded lazily
We will take a look at an example of the CanActivate guard in authentication. We will allow the user to access the user profile and friends pages only ...