Router Guards
In this lesson, we'll learn how router guards can prevent users from visiting routes they're not supposed to.
We'll cover the following...
We’re almost finished with authentication. One last thing we’ll implement is restricting access to specific routes in our application. Even though we’re not displaying the link to the secret page, users are technically still able to view the page if they input the URL in their address bar. The same applies vice versa. We don’t want to show the user the login or registration pages if they are logged in.
We can resolve these issues with router guards. A router guard is a class that runs before the component for the route loads. Angular will wait for a return value from the guard. The guard must return a boolean value. If the value is true
, the component for the route will load. If the value is false
, then the request is rejected. Router guards are the recommended way to ...