createStaticHandler
概要
サーバーサイドのデータローディングを実行するためのスタティックハンドラーを作成します。
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" } }
);
}シグネチャ
function createStaticHandler(
routes: RouteObject[],
opts?: CreateStaticHandlerOptions,
)パラメータ
routes
スタティックハンドラーを作成するための ルートオブジェクト です。
opts.basename
スタティックハンドラーのベース URL です (デフォルト: /)。
opts.future
スタティックハンドラーの future フラグです。
戻り値
指定された routes のデータをクエリするために使用できるスタティックハンドラーです。