Store Features

withRouteParams

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

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 , foor}) => ({ id, foo: +foo }))
{
  id: string;
  foo: number;
}

Methods

No methods are generated by this function.