Developer Preview Feature
DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!
Let us know so we can improve!
To learn how to use RouteHandlerFunction, see Server-Side Routing.
RouteHandlerFunction takes:
It returns a RouteHandlerViewResponse.
1type RouteHandlerFunction = (
2 viewRequest: ViewRequest,
3 handlerContext: HandlerContext,
4) => Promise<RouteHandlerViewResponse>;A ViewRequest object has to have:
requestPath)ViewRequest can optionally have any number of:
params)query)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.
1{
2 url: "/custom/thing?sort=desc
3 requestPath: "/custom/thing"
4 params?: { "param": "thing" }
5 query?: { "sort": "desc" }
6}A HandlerContext object has to have:
LwrRoute or an LwrErrorRoute objectRouteHandlerViewApi call1interface HandlerContext {
2 route: LwrRoute | LwrErrorRoute; // the current route from lwr.config.json
3 viewApi: RouteHandlerViewApi; // functions to call into the LWR server
4}The RouteHandlerViewApi calls the functions:
hasViewResponse
RouteHandlerView and a RecordgetViewResponse
RouteHandlerView and a RecordRouteHandlerViewResponse or undefined1interface 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}A RouteHandlerView object has this syntax:
1type RouteHandlerView = Pick<LwrRoute, 'contentTemplate' | 'layoutTemplate' | 'rootComponent'>;See Also
Developer Preview Feature