Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteTo add routing in Angular, define a Routes array that maps URL paths to components, register it with provideRouter(routes), place <router-outlet /> wherever routed views should appear, and use routerLink for navigation so the page changes without a full reload. Angular’s routing guides document this flow for standalone applications, and the steps below follow it.
Which setup this guide follows
The project’s Angular version and architecture change the registration code, so check them before copying anything. This walkthrough uses the standalone configuration that Angular’s current Define routes guide documents, where routes are registered with provideRouter. Angular also publishes version-specific guides; the Angular v20 Define routes page covers the same route-definition topics for that release. If your project still uses NgModules, follow the guide for your version and apply the same route definitions there.
As an Amazon Associate I earn from qualifying purchases.
Add routing in six steps
1. Define the routes
Create a Routes array that maps each path to a component. In Angular CLI projects, the documented conventional location is src/app/app.routes.ts.
import { Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { UserComponent } from './user/user.component';
import { NotFoundComponent } from './not-found/not-found.component';
export const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'user/:id', component: UserComponent },
{ path: '**', component: NotFoundComponent },
];
The :id segment is a path parameter, and ** is the wildcard that catches unmatched URLs. Route order is covered in its own section below.
#1 Best Overall
2. Register the router
In the standalone application configuration, add provideRouter(routes) to the providers array. The Router reference describes the Router and its related APIs if you need the terminology.
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes)],
};
3. Render the active view with router-outlet
Import RouterOutlet into the component that should host routed pages, then place <router-outlet /> in its template. The router inserts the component for the active URL at that location. The Show routes with Outlets guide covers rendering in detail.
import { Component } from '@angular/core';
import { RouterLink, RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
imports: [RouterOutlet, RouterLink],
template: `
<nav>
<a routerLink='/'>Home</a>
<a routerLink='/user/42'>User 42</a>
</nav>
<router-outlet />
`,
})
export class AppComponent {}
If the navigation bar stays visible while the content below it swaps, the outlet is working as intended. If nothing appears where the page should be, check this step first.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →4. Navigate with routerLink
Apply routerLink to standard anchor elements instead of plain href links for in-app navigation. The Navigate to routes guide explains the declarative approach, and the Router handles the transition in the browser so the application does not reload the page.
Rank #2
5. Add path parameters and child routes
A path such as user/:id exposes the variable segment to the routed component. ActivatedRoute provides route-specific information, including parameters and data.
import { Component, inject } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
export class UserComponent {
private route = inject(ActivatedRoute);
userId = this.route.snapshot.paramMap.get('id');
}
A snapshot reads the parameter once, when the component is created. If the same component stays on screen while the parameter changes, read the parameter through the route’s observables instead.
Use children when only a section of the page should change. The parent component must contain its own <router-outlet /> for the child views to render.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
export const routes: Routes = [
{
path: 'settings',
component: SettingsComponent,
children: [
{ path: 'profile', component: ProfileComponent },
{ path: 'security', component: SecurityComponent },
],
},
];
6. Lazy-load routes when it helps
loadComponent imports a standalone routed component only when its route becomes active. Whether that is worthwhile depends on the trade-off described in the next section.
Rank #3
{
path: 'reports',
loadComponent: () => import('./reports/reports.component').then(m => m.ReportsComponent),
},
How Angular chooses a route
Angular uses first-match-wins. It checks routes in the order they are configured and stops at the first match, so the order of the array decides which component renders. The Define routes guide sets out this behavior. Consider this configuration:
| Position | Route path | What it matches | Effect of this position |
|---|---|---|---|
| 1 | users/new | Only the literal URL /users/new | Reached only because it sits above the parameterized route |
| 2 | users/:id | Any single segment after /users/, such as /users/42 | If moved above users/new, /users/new would be captured with id set to “new” |
| 3 | ** |
Any URL that no earlier route matched | Must stay last, or it hides every route below it |
The rule is simple: specific paths first, parameterized paths next, and the wildcard last.
Path parameters and query parameters
Path and query parameters carry different kinds of state, and they are configured differently.
- Path parameters are part of the route definition, such as
user/:id. They identify a resource and must be present for the route to match. - Query parameters are separate URL state, such as
?tab=billing. They do not change which route matches.
Eager or lazy loading
Angular’s guidance is to consider eager loading for primary landing pages and lazy loading for other pages, while accounting for nested lazy-loading costs and the application’s performance needs. The Angular v20 Define routes guide covers both loading approaches.
Rank #4
| Consideration | Eager loading | Lazy loading with loadComponent |
|---|---|---|
| When the component’s code is fetched | With the initial application bundle | When its route first becomes active |
| Initial JavaScript | Includes the component | Can reduce the initial bundle |
| Later navigation | No code request when the route opens | Adds a request when the route opens; later data requests also apply |
| Angular’s suggested use | Primary landing pages | Other pages, after checking nested lazy-loading layers |
Angular does not give a universal performance threshold for choosing between the two. Measure startup time and the cost of the first visit to a lazy route in your own application before deciding a route’s loading strategy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Guards control navigation, not security
Angular’s documented guard types are CanActivate, CanActivateChild, CanDeactivate, and CanMatch. Each one can return a boolean, a UrlTree or RedirectCommand, or an Observable or Promise that produces one of those results. The Control route access with guards guide explains each type.
The CanMatch guard behaves differently from the others. When it returns false, the router tries the other routes that match the URL. This makes it useful for feature-dependent alternatives, where two routes share a path and a condition decides which one applies.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Angular’s route guard documentation is explicit about the limit of guards:
“Never rely on client-side guards as the sole source of access control.”
The guide explains that users can modify JavaScript running in the browser, so a guard can hide a page but cannot protect the data behind it. Authorization has to be enforced on the server for every request that returns protected data.
Troubleshooting common routing problems
- Nothing renders in a routed area. The component that should host the routed view is missing a
<router-outlet />, orRouterOutletis not in its imports. - A child route never appears. The parent route has no
childrenconfiguration, or the parent component lacks a nested outlet. - A specific route is never reached. A broader or parameterized route sits above it in the array. Move the specific route higher.
- Every unknown URL shows an unexpected page. The
**route is placed before other routes. Move it to the end of the array. - A protected page is hidden in the browser but its data is still reachable. Only a client-side guard is in place. Add the matching check on the server.
Routing works once the route array, the provider, an outlet in each host component, and correctly ordered paths are all in place. Each piece is small, so when a page fails to render, check them in that order.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




