From the course: Learning the Angular CLI
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Generating route guards - Angular Tutorial
From the course: Learning the Angular CLI
Generating route guards
- [Instructor] In Angular applications, we can protect routes using what is called a route guard. A route guard is used to perform certain checks when the route is being requested, and it can decide whether or not to continue with the navigation. In our particular case, we wish to lock certain routes, so that the user can't see data on this data logged in. Let's generate a new guard using the CLI; ng generate guard, and we will call this route guard auth. It will ask us which interface we would like to implement. For this example, we will choose the CanActivate guard, which moderates a navigation to a route. If true is returned, then it will continue navigation to the requested route. If false is returned, it will stop navigation. Now in the app routing module, we will first need to import this guard; import from /auth.guard. And let's go ahead and import our guard here. Then for the routes you want to protect, we can…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Creating new code with schematics49s
-
(Locked)
Generating components and modules2m 20s
-
(Locked)
Generating directives56s
-
(Locked)
Generating pipes45s
-
(Locked)
Generating route guards1m 39s
-
(Locked)
Adding libraries using schematics1m 9s
-
(Locked)
Generating custom library1m 27s
-
(Locked)
Challenge: Generating services31s
-
(Locked)
Solution: Generating services42s
-
(Locked)
-
-
-