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 routepersonRoute.useRoute().params.slug // stringThe 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.
Type Parameters
Section titled “Type Parameters”TPattern
Section titled “TPattern”TPattern extends string
Properties
Section titled “Properties”pattern
Section titled “pattern”
readonlypattern:TPattern
The pattern this definition was made from.
Methods
Section titled “Methods”fill()
Section titled “fill()”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.
Parameters
Section titled “Parameters”params
Section titled “params”RouteParams<TPattern>
Returns
Section titled “Returns”string
useRoute()
Section titled “useRoute()”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.
Returns
Section titled “Returns”TypedRoute<TPattern>