Skip to content

API Reference


API Reference / @dasch-ng/route-signals / routeQueryParam

Function: routeQueryParam()

routeQueryParam(key): Signal<string>

Defined in: route-query-param.ts:34

Creates a signal that tracks a URL-encoded query parameter and automatically decodes it.

This utility function extracts a query parameter from the current ActivatedRoute, automatically decodes URL-encoded values (e.g., spaces encoded as %20), and returns a signal that updates when the query parameter changes.

Parameters

key

string

The name of the query parameter to track

Returns

Signal<string>

A signal containing the decoded query parameter value

Throws

Error if the query parameter is not present in the current route

Example

typescript
// In a component
export class SearchComponent {
  // URL: /search?q=hello%20world&filter=active
  private readonly searchQuery = routeQueryParam('q');
  private readonly filter = routeQueryParam('filter');

  constructor() {
    console.log(this.searchQuery()); // "hello world" (decoded from "hello%20world")
    console.log(this.filter());      // "active"
  }
}

Released under the MIT License.