Skip to content

defineRouteData

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

defineRouteData<TContext, TData, TParams>(definition): RouteDataDefinition<TContext, TData, TParams>

Binds a route context tag to a loader.

const personData = defineRouteData({
context: 'people.person',
load: async ({ slug }, { signal }) => {
const response = await fetch(`/api/people/${encodeURIComponent(slug)}`, { signal })
return response.ok ? ((await response.json()) as Person) : NotFound
},
})

load receives the route’s parameters (annotate them to type them: ({ slug }: { slug: string })) and returns the data, or NotFound. It runs once per parameter set however many sections read it. The tag is the contract between this loader and the page: the page’s parameter node must carry the same one, and in development a section that reads a loader whose tag differs from the delivered one throws.

TContext extends string

TData

TParams extends Record<string, string> = Record<string, string>

TContext

(params, options) => Promise<NotFound | TData>

RouteDataDefinition<TContext, TData, TParams>