AI Hints
Home›Angular Tutorial›What Routing Is, Routes and router-outlet and routerLink
Angular · Lesson 73 of 120

What Routing Is

Pages in one app.

⏱ 2 min read▶ Video at 1:27:15🎓 Free
Watch this lesson in the Angular courseWatch on YouTube ↗Full Angular course

A shop has many pages. A home page, a list of books, a page for each book, and a basket. In Angular, the router gives us those pages.

  • Many pages
  • Home, books, basket
  • The router

Two kinds of websites

A classic website loads a whole new page from the server, for every link. An Angular app loads once. After that, the router swaps components on the screen, and changes the address. So moving between pages is instant.

Classic website

  • a new page per linkthe screen goes blankslower

Angular app

  • loads onceswaps componentsinstant

How the router works

The user goes to an address, like slash about. The router looks through a list of routes, for a matching path. It finds the component for that path. And it shows that component, in a place called the router outlet.

  1. Address: /about
  2. Find a matching route
  3. Its component: About
  4. Show it in <router-outlet>

The parts of routing

Routes are a list of paths, and components. Router outlet marks where the page appears. Router link makes links, that don't reload the page. And the router service lets code move between pages.

keyvalue
Routespaths and components
<router-outlet />where pages appear
routerLinklinks without reloading
Routernavigate in code

Summary

The router matches the address to a component, and shows it in the router outlet, without reloading. Next, defining routes.

Key takeaways
  • One app, many pages
  • Path → component
  • <router-outlet />
Next up: Routes and router-outlet — your first pages