routerLink
Directive that navigates to a route on click without a full reload.
Syntax
[routerLink]="commands" | routerLink="/path" Parameters
| Name | Type | Required | Description |
|---|---|---|---|
commands | string | any[] | No | Path string or array of route segments and params. |
Returns
directive — Performs in-app navigation on activation.
Examples
import { Component } from '@angular/core';
import { RouterLink } from '@angular/router';
@Component({
selector: 'app-nav',
standalone: true,
imports: [RouterLink],
template: `
<a routerLink="/">Home</a>
<a [routerLink]="['/users', user.id]"
[queryParams]="{ tab: 'info' }">Profile</a>
`,
})
export class NavComponent {
user = { id: 42 };
}
Notes
Import RouterLink into the component's imports. Use the array form for
dynamic segments and pair with queryParams, fragment, and relativeTo for
relative navigation. Prefer it over href to keep SPA navigation.