Router fundamentals and route configuration

Intermediate · 28 min

The Routes array, RouterOutlet, RouterLink, and provideRouter — the minimum setup every routed Angular app needs.

Before thisThe CLI, project anatomy, and standalone bootstrapping

A Coder's Journey · 28 min

Router fundamentals and route configuration

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by A Coder's JourneyReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A Routes array is just data — a list of path-to-component mappings — that `provideRouter()` registers with the app; the router itself is a service reading that data.
  • `<router-outlet>` is where the router actually renders whichever component matches the current URL — nothing renders there until a route matches.
  • `routerLink` navigates without a full page reload, which is the entire point of client-side routing — the browser never re-requests the page, only the matched component swaps in.

A single-page app still needs the illusion of pages

A plain client-rendered app, left on its own, has exactly one URL and one rendered view — there’s no built-in notion of “navigating to a different page” the way a traditional multi-page site has. Users expect that notion anyway: a distinct URL for /users versus /settings, a back button that works, bookmarkable links into specific views. The router is what reconstructs that expectation inside a single-page app, without actually reloading the page.

Routes: a plain data structure, not special syntax

export const routes: Routes = [
  { path: 'users', component: UserListComponent },
  { path: 'settings', component: SettingsComponent },
  { path: '', redirectTo: 'users', pathMatch: 'full' },
];
// app.config.ts
export const appConfig: ApplicationConfig = {
  providers: [provideRouter(routes)],
};

A Routes array is just data — an ordinary list of objects, each one mapping a path string to a component. There’s no magic in the array itself; all the actual behavior comes from provideRouter(routes) registering that data with Angular’s router service during bootstrap, the same provideX() pattern you’ve seen for HttpClient and the rest of the platform packages. The router reads this list, in order, trying to match the current URL against each entry’s path.

<router-outlet>: where the match actually renders

<nav>
  <a routerLink="/users">Users</a>
  <a routerLink="/settings">Settings</a>
</nav>
<router-outlet></router-outlet>

routerLink is the navigation half — clicking it asks the router to update the URL and find a matching route, without triggering a full browser page load. <router-outlet> is the rendering half: it’s a marker telling the router “insert whatever component matched the current route right here.” Nothing renders there until a route actually matches — it’s genuinely empty space otherwise, the same “inert until something renders it” relationship you’ve already seen with <ng-template>.

Together, these three pieces — the Routes data, provideRouter() registering it, and <router-outlet> as the render target — are the minimum a routed Angular app needs. Everything in the rest of this section (parameters, guards, nested routes, lazy loading) builds on exactly this foundation.

A plain <a href="/users"> would technically “work” in the sense that the browser would navigate there — but it would trigger a full page reload, re-bootstrapping the entire Angular app from scratch, discarding whatever state existed, just to end up showing the same single-page app again at a different URL. routerLink intercepts the click and hands navigation to the router instead, which updates the URL, matches the new route, and swaps the outlet’s content — all without the page ever actually reloading. That’s the entire value proposition of client-side routing, and it only works if navigation goes through the router rather than a plain anchor tag’s default browser behavior.

This lesson’s video builds routing into a real, from-scratch standalone- components app as part of an ongoing series — worth watching for how routing fits alongside the rest of a real app’s structure, not in isolation. The linked “deeper” video focuses specifically on the modern provideRouter() standalone setup if you want a second, more concentrated pass on just that piece.

Check yourself

  1. 01Given `const routes: Routes = [{ path: 'users', component: UserListComponent }]`, what has to also exist in the template for navigating to `/users` to actually show anything?

    A `<router-outlet></router-outlet>` somewhere in the app's rendered template. The Routes array only describes the mapping from a path to a component — the outlet is the actual spot in the DOM where the router inserts whatever component matched, and without one present, a matching route has nowhere to render into.

  2. 02What's the practical difference between `<a href="/users">` and `<a routerLink="/users">` in a routed Angular app?

    A plain `href` triggers a full browser navigation — a new page load, the entire app re-bootstrapping from scratch. `routerLink` intercepts the click and asks Angular's router to handle it client-side instead, swapping the matched component into the existing `<router-outlet>` with no page reload at all, which is the actual value client-side routing provides.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark