Skip to content

API Reference


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

Function: routeData()

routeData<T>(key): Signal<T | NonNullable<T>>

Defined in: route-data.ts:41

Creates a signal that tracks a route data property.

This utility function extracts a data property from the current ActivatedRoute and returns a signal that updates when the route data changes. Route data is typically configured in the route configuration and can be used to pass static data to components.

Type Parameters

T

T

The type of the data property

Parameters

key

string

The name of the data property to track

Returns

Signal<T | NonNullable<T>>

A signal containing the route data value

Throws

Error if the data property is not present in the current route

Example

typescript
// In route configuration:
// {
//   path: 'admin',
//   component: AdminComponent,
//   data: { title: 'Admin Dashboard', role: 'admin' }
// }

// In a component
export class AdminComponent {
  private readonly title = routeData<string>('title');
  private readonly role = routeData<string>('role');

  constructor() {
    console.log(this.title()); // "Admin Dashboard"
    console.log(this.role());  // "admin"
  }
}

Released under the MIT License.