Store Features

withRouteParams

Deprecated: Use withRoute instead, which also supports queryParams.

This store feature provides access to the route params. The mapParams receives the route params object, use it to transform it to an object, this will create a computed for each prop return by the mapParams function

Usage Notes: The store to be provided in a routed component, since this feature consumes from Angular's ActivatedRoute. Providing it in root or in a route-level factory is not sufficient.

Examples

Transform url params into store props

// example route  /products/:id/
const ProductDetailStore = signalStore(
  withRouteParams(({ id }) => ({ id })),
  withCalls(() => ({
    loadProductDetail: (id: string) =>
      inject(ProductService).getProductDetail(id),
  })),
  withHooks(({ loadProductDetail, id }) => ({
    onInit: () => {
      loadProductDetail(id());
    },
  })),
);
Property Description Value
mapParams A function to transform the params before they are stored. (params: Params, data?: any) => T,

State

No state signals are generated.

Computed

Generates a computed signals, per prop returned by the mapParams function.

// for  withRouteParams(({ id , foo }) => ({ id, foo: +foo }))
{
  id: string;
  foo: number;
}

Methods

No methods are generated by this function.