Skip to content

createExternalRoute

ts
export function createExternalRoute<
  const TName extends string | undefined = undefined,
  const TPath extends string | Path | undefined = undefined,
  const TQuery extends string | Query | undefined = undefined,
  const THost extends string | Host | undefined = undefined
>(options: CreateRouteOptionsWithoutParent<TName, TPath, TQuery, THost>): Route<ToName<TName>, ToHost<THost>, ToPath<TPath>, ToQuery<TQuery>>

export function createExternalRoute<
  const TParent extends Route,
  const TName extends string | undefined = undefined,
  const TPath extends string | Path | undefined = undefined,
  const TQuery extends string | Query | undefined = undefined
>(options: CreateRouteOptionsWithParent<TParent, TName, TPath, TQuery, Host<'', {}>>): Route<CombineName<TParent['name'], ToName<TName>>, ToHost<Host<'', {}>>, CombinePath<TParent['path'], ToPath<TPath>>, CombineQuery<TParent['query'], ToQuery<TQuery>>>

Creates an individual route record for your router.

Type parameters

Type parameterDescription
TParent extends Route | undefinedThe parent route for this route.
TName extends string | undefinedOptional name, will be used for navigating and matching.
TPath extends Path | string | undefinedThe optional path part of your route.
TQuery extends Query | string | undefinedThe optional query part of your route.
THost extends Host | string | undefinedThe optional host part of your route.

Parameters

ParameterTypeDescription
options?CreateRouteOptionsRoute configuration options.

Returns

Route<T>

Single Route instance.

Example

ts
import { createExternalRoute } from '@kitbag/router'

const routerDocs = createExternalRoute({
  host: 'https://router.kitbag.dev',
  name: 'docs',
})

const routerApiDocs = createExternalRoute({
  parent: routerDocs,
  name: 'api',
  path: '/api/[topic]',
})

export const documentationRoutes = [routerDocs, routerApiDocs]