October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Link to a Route with RouterLink in Angular

Add RouterLink to an Angular template to navigate to configured routes, including routes with dynamic parameters, query values, or fragments.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Angular’s RouterLink directive on a template link to navigate to a route inside your application. Import RouterLink from @angular/router, add it to a standalone component’s imports, and set the link’s destination with routerLink.

Basic RouterLink setup

This standalone component links to the /user-profile route:

As an Amazon Associate I earn from qualifying purchases.

import {Component} from '@angular/core';
import {RouterLink} from '@angular/router';

@Component({
  standalone: true,
  imports: [RouterLink],
  template: `<a routerLink="/user-profile">User profile</a>`,
})
export class App {}

Use RouterLink where the template should present navigation as a link. The destination needs to match a route configured in the application. Angular’s RouterLink API reference describes the directive as making a template element a link that initiates navigation to a route.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a string path or command array

Use a string for a straightforward path

A simple route can be written directly as a string:

<a routerLink="/about">About</a>

Use an array to build a route

Command arrays are useful when a path has multiple segments or includes values from component data. For example, to link to a user whose ID is stored in userId:

<a [routerLink]="['/users', userId]">View user</a>

For a route with several segments, place each segment or dynamic value in the array:

<a [routerLink]="['/team', teamId, 'user', userId]">View team member</a>

The directive also accepts a UrlTree or a nullish value. A null or undefined destination effectively disables the link. See the accepted input types and options in the RouterLink API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Resolve links from the right route level

A leading slash makes a destination absolute from the application root. A path without a leading slash, or one prefixed with ./, is resolved relative to the current activated route. Use ../ to move up one level in the route tree.

This distinction matters in nested routes: RouterLink commands are interpreted as a change from the current URL unless you start at the root. If a relative link resolves somewhere unexpected, check which route is active where the link is rendered and whether the destination should begin with /.

Add query parameters and a fragment

Bind query values with queryParams and set a fragment with fragment:

<a [routerLink]="['/user', userId]"
   [queryParams]="{tab: 'details'}"
   fragment="education">
  User details
</a>

This builds a link to the user route with a tab=details query parameter and an education fragment. To combine new query parameters with existing ones, use queryParamsHandling; its options include merging new values or preserving the current query values. The API also provides preserveFragment when a link should retain the current fragment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When supplying a UrlTree as the RouterLink input, the API does not allow queryParams, fragment, queryParamsHandling, preserveFragment, or relativeTo to be used with that input. Check the API reference for the full set of inputs, including navigation state and URL-handling options.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

RouterLink or Router.navigate()?

Use RouterLink when navigation is represented by a link in the template. Use Router.navigate() when code needs to decide whether or where to navigate based on application logic or state. Angular’s routing guide explains how routes, links, and routed content fit together.

How navigation fits into an Angular app

Angular routing maps URLs to components, and RouterOutlet marks where routed content is rendered. For in-app navigation, the client-side router updates the application’s routed view rather than requiring a full page request for each route change. The Angular routing guide covers the broader routing setup.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.