Skip to content

query

ts
function query<TQuery, TParams>(query, params): Query<TQuery, TParams>

Constructs a Query object, which enables assigning types for params.

Type parameters

Type parameterDescription
TQuery extends stringThe string literal type that represents the query.
TParams extends QueryParams<TQuery>The type of the query parameters associated with the query.

Parameters

ParameterTypeDescription
queryTQueryThe query string.
paramsIdentity<TParams>The parameters associated with the query, typically as key-value pairs.

Returns

Query<TQuery, TParams>

An object representing the query which includes the query string, its parameters, and a toString method for getting the query as a string.

Example

ts
import { createRoute, query } from '@kitbag/router'

export const home = createRoute({
  name: 'home',
  query: query('bar=[bar]', { bar: Boolean }),
  component: Home
})

Custom Params

Param types is customizable with ParamGetter, ParamSetter, and ParamGetSet. Read more about custom params.