| 1 |
|
| 2 | import { Location } from "../router/history.js";
|
| 3 | import { DataRouteObject, RouteBranch, RouteObject } from "../router/utils.js";
|
| 4 | import { FutureConfig, Router, StaticHandlerContext } from "../router/router.js";
|
| 5 | import * as React$1 from "react";
|
| 6 |
|
| 7 | //#region lib/dom/server.d.ts
|
| 8 | /**
|
| 9 | * @category Types
|
| 10 | */
|
| 11 | interface StaticRouterProps {
|
| 12 | /**
|
| 13 | * The base URL for the static router (default: `/`)
|
| 14 | */
|
| 15 | basename?: string;
|
| 16 | /**
|
| 17 | * The child elements to render inside the static router
|
| 18 | */
|
| 19 | children?: React$1.ReactNode;
|
| 20 | /**
|
| 21 | * The {@link Location} to render the static router at (default: `/`)
|
| 22 | */
|
| 23 | location: Partial<Location> | string;
|
| 24 | }
|
| 25 | /**
|
| 26 | * A {@link Router | `<Router>`} that may not navigate to any other {@link Location}.
|
| 27 | * This is useful on the server where there is no stateful UI.
|
| 28 | *
|
| 29 | * @public
|
| 30 | * @category Declarative Routers
|
| 31 | * @mode declarative
|
| 32 | * @param props Props
|
| 33 | * @param {StaticRouterProps.basename} props.basename n/a
|
| 34 | * @param {StaticRouterProps.children} props.children n/a
|
| 35 | * @param {StaticRouterProps.location} props.location n/a
|
| 36 | * @returns A React element that renders the static {@link Router | `<Router>`}
|
| 37 | */
|
| 38 | declare function StaticRouter({
|
| 39 | basename,
|
| 40 | children,
|
| 41 | location: locationProp
|
| 42 | }: StaticRouterProps): React$1.JSX.Element;
|
| 43 | /**
|
| 44 | * @category Types
|
| 45 | */
|
| 46 | interface StaticRouterProviderProps {
|
| 47 | /**
|
| 48 | * The {@link StaticHandlerContext} returned from {@link StaticHandler}'s
|
| 49 | * `query`
|
| 50 | */
|
| 51 | context: StaticHandlerContext;
|
| 52 | /**
|
| 53 | * The static {@link DataRouter} from {@link createStaticRouter}
|
| 54 | */
|
| 55 | router: Router;
|
| 56 | /**
|
| 57 | * Whether to hydrate the router on the client (default `true`)
|
| 58 | */
|
| 59 | hydrate?: boolean;
|
| 60 | /**
|
| 61 | * The [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
|
| 62 | * to use for the hydration [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
|
| 63 | * tag
|
| 64 | */
|
| 65 | nonce?: string;
|
| 66 | }
|
| 67 | /**
|
| 68 | * A {@link DataRouter} that may not navigate to any other {@link Location}.
|
| 69 | * This is useful on the server where there is no stateful UI.
|
| 70 | *
|
| 71 | * @example
|
| 72 | * export async function handleRequest(request: Request) {
|
| 73 | * let { query, dataRoutes } = createStaticHandler(routes);
|
| 74 | * let context = await query(request));
|
| 75 | *
|
| 76 | * if (context instanceof Response) {
|
| 77 | * return context;
|
| 78 | * }
|
| 79 | *
|
| 80 | * let router = createStaticRouter(dataRoutes, context);
|
| 81 | * return new Response(
|
| 82 | * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
|
| 83 | * { headers: { "Content-Type": "text/html" } }
|
| 84 | * );
|
| 85 | * }
|
| 86 | *
|
| 87 | * @public
|
| 88 | * @category Data Routers
|
| 89 | * @mode data
|
| 90 | * @param props Props
|
| 91 | * @param {StaticRouterProviderProps.context} props.context n/a
|
| 92 | * @param {StaticRouterProviderProps.hydrate} props.hydrate n/a
|
| 93 | * @param {StaticRouterProviderProps.nonce} props.nonce n/a
|
| 94 | * @param {StaticRouterProviderProps.router} props.router n/a
|
| 95 | * @returns A React element that renders the static router provider
|
| 96 | */
|
| 97 | declare function StaticRouterProvider({
|
| 98 | context,
|
| 99 | router,
|
| 100 | hydrate,
|
| 101 | nonce
|
| 102 | }: StaticRouterProviderProps): React$1.JSX.Element;
|
| 103 | /**
|
| 104 | * Create a static {@link DataRouter} for server-side rendering
|
| 105 | *
|
| 106 | * @example
|
| 107 | * export async function handleRequest(request: Request) {
|
| 108 | * let { query, dataRoutes } = createStaticHandler(routes);
|
| 109 | * let context = await query(request);
|
| 110 | *
|
| 111 | * if (context instanceof Response) {
|
| 112 | * return context;
|
| 113 | * }
|
| 114 | *
|
| 115 | * let router = createStaticRouter(dataRoutes, context);
|
| 116 | * return new Response(
|
| 117 | * ReactDOMServer.renderToString(<StaticRouterProvider ... />),
|
| 118 | * { headers: { "Content-Type": "text/html" } }
|
| 119 | * );
|
| 120 | * }
|
| 121 | *
|
| 122 | * @public
|
| 123 | * @category Data Routers
|
| 124 | * @mode data
|
| 125 | * @param routes The route objects to create a static {@link DataRouter} for
|
| 126 | * @param context The {@link StaticHandlerContext} returned from {@link StaticHandler}'s
|
| 127 | * `query`
|
| 128 | * @param opts Options
|
| 129 | * @param opts.future Future flags for the static {@link DataRouter}
|
| 130 | * @param opts.branches Optional pre-computed route branches
|
| 131 | * @returns A static {@link DataRouter} that can be used to render the provided routes
|
| 132 | */
|
| 133 | declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext, opts?: {
|
| 134 | branches?: RouteBranch<DataRouteObject>[];
|
| 135 | future?: Partial<FutureConfig>;
|
| 136 | }): Router;
|
| 137 | //#endregion
|
| 138 | export { StaticRouter, StaticRouterProps, StaticRouterProvider, StaticRouterProviderProps, createStaticRouter }; |
| \ | No newline at end of file |