Router fundamentals and route configuration
The Routes array, RouterOutlet, RouterLink, and provideRouter — the minimum setup every routed Angular app needs.
Router fundamentals and route configuration
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
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.
Why routerLink instead of a plain href
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
Given `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.
What'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
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.