createStaticRouter
On this page

createStaticRouter

Summary

Reference Documentation ↗

Create a static DataRouter for server-side rendering

export async function handleRequest(request: Request) {
  let { query, dataRoutes } = createStaticHandler(routes);
  let context = await query(request);

  if (context instanceof Response) {
    return context;
  }

  let router = createStaticRouter(dataRoutes, context);
  return new Response(
    ReactDOMServer.renderToString(<StaticRouterProvider ... />),
    { headers: { "Content-Type": "text/html" } }
  );
}

Signature

function createStaticRouter(
  routes: RouteObject[],
  context: StaticHandlerContext,
  opts: {},
)

Params

routes

The route objects to create a static DataRouter for

context

The StaticHandlerContext returned from StaticHandler's query

opts.future

Future flags for the static DataRouter

opts.branches

Deprecated optional pre-computed route branches. This option is no longer used because branch caching is done automatically inside the static router.

Returns

A static DataRouter that can be used to render the provided routes

Docs and examples CC 4.0
Edit