Enhancing navigation with advanced features
So far, we have covered basic routing, with route parameters as well as query parameters. The Angular router is quite capable, though, and able to do much more, such as the following:
- Controlling access to a route
- Preventing navigation away from a route
- Prefetching data to improve the UX
- Lazy-loading routes to speed up the response time
In the following sections, we will learn about all these techniques in more detail.
Controlling route access
When we want to prevent unauthorized access to a particular route, we use a specific Angular concept called a guard. An Angular guard can be of the following types:
- canActivate: Controls whether a route can be activated.
- canActivateChild: Controls access to child routes of a route.
- canDeactivate: Controls whether a route can be deactivated. Deactivation happens when we navigate away from a route.
- canLoad...