October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Read Route State in Angular

Use Angular’s ActivatedRoute snapshot for a one-time read and its observables when component state must respond to route changes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inject ActivatedRoute from @angular/router. For a one-time value, read route.snapshot; when the component must update as navigation changes, use the route’s observables, such as paramMap, queryParamMap, or data. A snapshot is point-in-time state, not a live view. Angular’s route-state guide and ActivatedRoute API reference document these options.

What route state does ActivatedRoute expose?

ActivatedRoute represents the route node associated with a component loaded in a router outlet. It exposes that route’s URL segments and parameters, query parameters and fragment, route data, and links to related nodes in the route tree. The API reference lists the available properties.

As an Amazon Associate I earn from qualifying purchases.

Route parameters and query parameters are different scopes. Parameters such as an identifier in a route path belong to a route node; query parameters are available across routes. Use paramMap or params for route parameters, and queryParamMap or queryParams for query parameters. The map APIs let you retrieve values by key and support multiple values for the same parameter. See Angular’s route-state guide.

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

Choose a snapshot or an observable

Need Use What to account for
Read the initial value once route.snapshot.paramMap or another snapshot property Synchronous and simple, but it does not update when the route later changes.
Update when route parameters change route.paramMap or route.params Handle observable emissions and manage the subscription lifecycle.
Update when query parameters change route.queryParamMap or route.queryParams Query parameters are shared across routes.
React to route data or a fragment route.data or route.fragment These are observables; use snapshots if a one-time read is sufficient.

Angular describes navigation as events over time and a snapshot as the router state at a particular moment. That distinction matters when the router reuses a component while changing its route parameters. In that case, a snapshot read made at initialization will not keep the component’s displayed state current. See Read route state and ActivatedRouteSnapshot.

Read a parameter once

Use a snapshot when the component only needs the value available at the time it is created or initialized:

import {Component, inject} from '@angular/core';
import {ActivatedRoute} from '@angular/router';

@Component({/* ... */})
export class UserProfile {
  private route = inject(ActivatedRoute);
  readonly userId = this.route.snapshot.paramMap.get('id');
}

paramMap.get('id') returns the route parameter value for the key id. If later navigation can change that value while this component remains active, use an observable instead.

React to route parameter changes

Subscribe to paramMap when the component should respond as the active route changes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import {Component, inject} from '@angular/core';
import {ActivatedRoute} from '@angular/router';

@Component({/* ... */})
export class UserProfile {
  private route = inject(ActivatedRoute);

  constructor() {
    this.route.paramMap.subscribe((params) => {
      const userId = params.get('id');
      // Update component state for the active user.
    });
  }
}

For query-string values, subscribe to queryParamMap or queryParams. For route data and URL fragments, use data and fragment, respectively. These properties are observables on ActivatedRoute; choose the ones matching the state your component needs. The API reference documents them.

Read values from another route node

The injected route corresponds to the component’s own node in the route tree. If the value belongs to an ancestor route, inspect route.parent or walk route.pathFromRoot. For descendant routes, use route.children or route.firstChild. The snapshot has corresponding tree relationships. Be deliberate about which node owns a route parameter: a parent’s route-specific parameter is not the same thing as a query parameter shared across routes. See ActivatedRoute, ActivatedRouteSnapshot, and Angular’s router reference.

Access resolved route data

A resolver can prepare data before a route activates. Its function receives an ActivatedRouteSnapshot and a RouterStateSnapshot; it can obtain an identifier from route.paramMap and use it to resolve the required value. The activated component can then read resolved values from route.data or its snapshot. Angular’s route data resolvers guide shows the resolver pattern.

Reading query-parameter changes and rerunning a resolver are separate behaviors. By default, Angular’s guard and resolver policy is paramsChange, which does not include query-parameter changes. If a resolver must rerun when query parameters change, select a query-aware policy from the options in the RunGuardsAndResolvers API.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep URL-backed filters in sync

For sorting, filters, or pagination represented in the query string, observe the query parameters and navigate with the updated value. Angular’s guide demonstrates merging the new value so existing query parameters are retained:

router.navigate([], {
  queryParams: {sort},
  queryParamsHandling: 'merge'
});

The empty commands array applies the query update without adding a new path segment. The merge setting preserves other query values while applying the supplied update. See Read route state.

Behavior to keep in mind

  • Snapshots do not change. Treat them as a read of route state at a particular moment, not as a subscription to future navigation.
  • Observable emissions use shallow equality. The ActivatedRoute API notes that its observables emit when current and previous values differ by shallow equality. Mutating a nested resolved-data object without changing the outer value does not, by itself, cause data to emit. See the API reference.
  • Resolver policy affects refresh timing. A query-parameter update does not trigger a resolver under the default paramsChange policy; use an appropriate query-aware option when that behavior is required.

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.

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.