Skip to content

API Reference


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

Function: routeParam()

routeParam(key): Signal<string>

Defined in: route-param.ts:35

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

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

Parameters

key

string

The name of the route parameter to track

Returns

Signal<string>

A signal containing the decoded route parameter value

Throws

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

Example

typescript
// In a component
export class MyComponent {
  // Route: /domains/:domainId/groups/:groupId
  private readonly domainId = routeParam('domainId');
  private readonly groupId = routeParam('groupId');

  constructor() {
    // If URL is /domains/my-domain/groups/a%20b
    console.log(this.domainId()); // "my-domain"
    console.log(this.groupId());  // "a b" (decoded from "a%20b")
  }
}

Released under the MIT License.