CHAPTER 10
Beginner
Angular Routing and Navigation
Updated: May 18, 2026
5 min read
# CHAPTER 10
Angular Routing and Navigation
1. Chapter Introduction
A Single Page Application needs to display different "pages" (views) without ever reloading the browser. Angular's Router module handles this by listening to URL changes and swapping in the appropriate Component. This chapter covers everything from basic route setup to advanced lazy loading for performance.2. Learning Objectives
- Configure the Angular Router with routes.
-
Use
routerLinkfor navigation.
-
Read route parameters with
ActivatedRoute.
- Implement child routes for nested layouts.
- Enable lazy loading for feature modules.
3. Setting Up Routes
app.routes.ts
app.config.ts
4. The Router Outlet
The<router-outlet> acts as a placeholder in your main template. Angular injects the active route's component here.
html
5. Navigation Links with routerLink and routerLinkActive
html
routerLinkActive automatically adds the CSS class active to the link whose route matches the current URL!
6. Route Parameters
typescript
product-detail.component.ts
html
7. Programmatic Navigation
typescript
8. Lazy Loading
Instead of loading all components upfront, lazy loading fetches feature modules only when the user navigates to them — dramatically improving initial load time.
typescript
9. Child Routes
typescript
html
10. Mini Project: Multi-Page Angular App
text
11. Common Mistakes
-
Using
hrefinstead ofrouterLink:<a href="/about">causes a full page reload, defeating the purpose of SPA. Always userouterLink.
-
Missing
<router-outlet>: If you configure routes but don't place<router-outlet>in the template, components will never render.
12. MCQs with Answers
Question 1
What Angular element acts as a placeholder where the active route's component is rendered?
Question 2
What directive is used for navigation links instead of the standard href?
Question 3
What wildcard path
Question 4
How do you read a route parameter like :id from the URL?
Question 5
What is Lazy Loading in Angular routing?
Question 6
What directive automatically adds a CSS class when the router link matches the current URL?
Question 7
Which service is used for programmatic navigation (navigating via TypeScript code)?
Question 8
In router.navigate(['/dashboard']), what is the argument?
Question 9
What is the syntax for lazy loading a module in route configuration?
Question 10
What is the path for a default/home route?
13. Interview Questions
-
Q: What is the difference between ActivatedRoute
andRouterservices?
- Q: Explain how lazy loading improves Angular application performance.
14. Summary
Angular's Router transforms a collection of components into a coherent multi-page application. By using routerLink for navigation, <router-outlet>` for rendering, and lazy loading for performance, Angular developers can build applications with dozens of views that feel as fast as a desktop application.