Skip to content

Functions: path()

ts
function path<TPath, TParams>(value, 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 PathParamsWithParamNameExtracted<TPath>The type of the path parameters associated with the path.

Parameters

ParameterTypeDescription
valueTPathThe 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 routes = createRoute({
  name: 'home',
  path: path('/[foo]', { foo: Number }),
  component: Home
})