RouteHandlerFunction

To learn how to use RouteHandlerFunction, see Server-Side Routing.

Syntax 

RouteHandlerFunction takes:

It returns a RouteHandlerViewResponse.

RouteHandlerFunction
1type RouteHandlerFunction = (
2  viewRequest: ViewRequest,
3  handlerContext: HandlerContext,
4) => Promise<RouteHandlerViewResponse>;

ViewRequest 

A ViewRequest object has to have:

  • a URL
  • a path (requestPath)

ViewRequest can optionally have any number of:

  • parameters (params)
  • queries (query)
ViewRequest
1// Request: given GET http://www.example.com/custom/thing?sort=desc
2interface ViewRequest {
3  url: string; // "/custom/thing?sort=desc
4  requestPath: string; // "/custom/thing"
5  params?: Record<string, string>; // { "param": "thing" }
6  query?: Record<string, undefined | string | string[]>; // { "sort": "desc" }
7}

For example, the ViewRequest object for the request get http://www.example.com/custom/thing?sort=desc looks like this.

Example ViewRequest
1{
2  url: "/custom/thing?sort=desc
3  requestPath: "/custom/thing"
4  params?: { "param": "thing" }
5  query?: { "sort": "desc" }
6}

HandlerContext 

A HandlerContext object has to have:

HandlerContext
1interface HandlerContext {
2  route: LwrRoute | LwrErrorRoute; // the current route from lwr.config.json
3  viewApi: RouteHandlerViewApi; // functions to call into the LWR server
4}

RouteHandlerViewApi 

The RouteHandlerViewApi calls the functions:

RouteHandlerViewApi
1interface RouteHandlerViewApi {
2  // interact with the LWR rendered page view cache
3  hasViewResponse(view: RouteHandlerView, viewParams?: Record<string, Json>): boolean;
4  getViewResponse(
5    view: RouteHandlerView,
6    viewParams?: Record<string, Json>,
7  ): Promise<RouteHandlerViewResponse | undefined>;
8}

RouteHandlerView 

A RouteHandlerView object has this syntax:

RouteHandlerView
1type RouteHandlerView = Pick<LwrRoute, 'contentTemplate' | 'layoutTemplate' | 'rootComponent'>;

See Also

Developer Preview Feature

Feature is available as a developer preview. Feature is not generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All commands, parameters, and other features are subject to change or deprecation at any time, with or without notice. Do not implement functionality developed with these commands or tools.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!