Skip to content

path

ts
function path<TPath, TParams>(path, params): Path<TPath, TParams>

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

Type parameters

Type parameterDescription
TPath extends stringThe string literal type that represents the path.
TParams extends PathParams<TPath>The type of the path parameters associated with the path.

Parameters

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

Returns

Path<TPath, TParams>

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

Example

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

export const home = createRoute({
  name: 'home',
  path: path('/[foo]', { foo: Number }),
  component: Home
})

Custom Params

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