Skip to content

Functions: query()

ts
function query<TQuery, TParams>(value, 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 QueryParamsWithParamNameExtracted<TQuery>The type of the query parameters associated with the query.

Parameters

ParameterTypeDescription
valueTQueryThe 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 routes = createRoute({
  name: 'home',
  query: query('bar=[bar]', { bar: Boolean }),
  component: Home
})