StaticRouterProvider
On this page

StaticRouterProvider

Summary

Reference Documentation ↗

A Data Router that may not navigate to any other location. This is useful on the server where there is no stateful UI.

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 StaticRouterProvider({
  context,
  router,
  hydrate = true,
  nonce,
}: StaticRouterProviderProps)

Props

context

The StaticHandlerContext returned from staticHandler.query()

router

The static data router from createStaticRouter

hydrate

Whether to hydrate the router on the client (default true)

nonce

The nonce to use for the hydration <script> tag

Docs and examples CC 4.0
Edit