@@ -46,7 +46,14 @@ export interface StaticRouterProps {
46
46
* A `<Router>` that may not navigate to any other location. This is useful
47
47
* on the server where there is no stateful UI.
48
48
*
49
+ * @public
49
50
* @category Declarative Routers
51
+ * @mode declarative
52
+ * @param props Props
53
+ * @param props.basename The base URL for the static router (default: `/`)
54
+ * @param props.children The child elements to render inside the static router
55
+ * @param props.location The location to render the static router at (default: `/`)
56
+ * @returns A React element that renders the static router
50
57
*/
51
58
export function StaticRouter ( {
52
59
basename,
@@ -90,7 +97,32 @@ export interface StaticRouterProviderProps {
90
97
* A Data Router that may not navigate to any other location. This is useful
91
98
* on the server where there is no stateful UI.
92
99
*
100
+ * @example
101
+ * export async function handleRequest(request: Request) {
102
+ * let { query, dataRoutes } = createStaticHandler(routes);
103
+ * let context = await query(request));
104
+ *
105
+ * if (context instanceof Response) {
106
+ * return context;
107
+ * }
108
+ *
109
+ * let router = createStaticRouter(dataRoutes, context);
110
+ * return new Response(
111
+ * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
112
+ * { headers: { "Content-Type": "text/html" } }
113
+ * );
114
+ * }
115
+ *
116
+ * @public
93
117
* @category Data Routers
118
+ * @mode data
119
+ * @param props Props
120
+ * @param props.context The {@link StaticHandlerContext} returned from `staticHandler.query()`
121
+ * @param props.router The static data router from {@link createStaticRouter}
122
+ * @param props.hydrate Whether to hydrate the router on the client (default `true`)
123
+ * @param props.nonce The [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
124
+ * to use for the hydration `<script>` tag
125
+ * @returns A React element that renders the static router provider
94
126
*/
95
127
export function StaticRouterProvider ( {
96
128
context,
@@ -255,7 +287,32 @@ type CreateStaticHandlerOptions = Omit<
255
287
> ;
256
288
257
289
/**
258
- * @category Utils
290
+ * Create a static handler to perform server-side data loading
291
+ *
292
+ * @example
293
+ * export async function handleRequest(request: Request) {
294
+ * let { query, dataRoutes } = createStaticHandler(routes);
295
+ * let context = await query(request));
296
+ *
297
+ * if (context instanceof Response) {
298
+ * return context;
299
+ * }
300
+ *
301
+ * let router = createStaticRouter(dataRoutes, context);
302
+ * return new Response(
303
+ * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
304
+ * { headers: { "Content-Type": "text/html" } }
305
+ * );
306
+ * }
307
+ *
308
+ * @public
309
+ * @category Data Routers
310
+ * @mode data
311
+ * @param routes The route objects to create a static handler for
312
+ * @param opts Options
313
+ * @param opts.basename The base URL for the static handler (default: `/`)
314
+ * @param opts.future Future flags for the static handler
315
+ * @returns A static handler that can be used to query data for the provided routes
259
316
*/
260
317
export function createStaticHandler (
261
318
routes : RouteObject [ ] ,
@@ -268,7 +325,32 @@ export function createStaticHandler(
268
325
}
269
326
270
327
/**
328
+ * Create a static data router for server-side rendering
329
+ *
330
+ * @example
331
+ * export async function handleRequest(request: Request) {
332
+ * let { query, dataRoutes } = createStaticHandler(routes);
333
+ * let context = await query(request));
334
+ *
335
+ * if (context instanceof Response) {
336
+ * return context;
337
+ * }
338
+ *
339
+ * let router = createStaticRouter(dataRoutes, context);
340
+ * return new Response(
341
+ * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
342
+ * { headers: { "Content-Type": "text/html" } }
343
+ * );
344
+ * }
345
+ *
346
+ * @public
271
347
* @category Data Routers
348
+ * @mode data
349
+ * @param routes The route objects to create a static data router for
350
+ * @param context The static handler context returned from `staticHandler.query()`
351
+ * @param opts Options
352
+ * @param opts.future Future flags for the static data router
353
+ * @returns A static data router that can be used to render the provided routes
272
354
*/
273
355
export function createStaticRouter (
274
356
routes : RouteObject [ ] ,
0 commit comments