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.
Type Parameters
Section titled “Type Parameters”TContext
Section titled “TContext”TContext extends string
TData
TParams
Section titled “TParams”TParams extends Record<string, string> = Record<string, string>
Parameters
Section titled “Parameters”definition
Section titled “definition”context
Section titled “context”TContext
(params, options) => Promise<NotFound | TData>
Returns
Section titled “Returns”RouteDataDefinition<TContext, TData, TParams>