Skip to content

RouteDefinition

Describes@ebitex/content-sdk 1.xSee the changelog:@ebitex/content-sdk

The typed form of a route. Declare the pattern once, where the compiler can read it, and every use of it is checked: fill() takes exactly the parameters the pattern names, and useRoute() hands a renderer those parameters as strings.

const personRoute = defineRoute('/people/{slug}')
personRoute.fill({ slug: 'ada' }) // '/people/ada'
personRoute.fill({ id: 'ada' }) // compile error: 'id' is not a parameter of this route
personRoute.useRoute().params.slug // string

The pattern string is written by hand and must match the one the site’s address uses. In development, useRoute() warns once when the page delivered under it names different parameters.

TPattern extends string

readonly pattern: TPattern

The pattern this definition was made from.

fill(params): string

Fills the pattern with values (percent-encoded). Throws on a missing or empty value; the compiler already refuses a missing or unknown name.

RouteParams<TPattern>

string


useRoute(): TypedRoute<TPattern>

The current route, with params typed from the pattern. A React hook: call it in a renderer rendered by <Experience>. On a page that is not this route (or outside <Experience>) the values are absent at run time, so use it only in renderers that belong to the route.

TypedRoute<TPattern>