UNPKG

73.1 kBTypeScriptView Raw
1import { AsyncLocalStorage } from 'node:async_hooks';
2import * as React from 'react';
3export { Await, BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, unstable_HistoryRouter } from 'react-router/internal/react-server-client';
4import { ParseOptions, SerializeOptions } from 'cookie';
5export { ParseOptions as CookieParseOptions, SerializeOptions as CookieSerializeOptions } from 'cookie';
6
7/**
8 * Actions represent the type of change to a location value.
9 */
10declare enum Action {
11 /**
12 * A POP indicates a change to an arbitrary index in the history stack, such
13 * as a back or forward navigation. It does not describe the direction of the
14 * navigation, only that the current index changed.
15 *
16 * Note: This is the default action for newly created history objects.
17 */
18 Pop = "POP",
19 /**
20 * A PUSH indicates a new entry being added to the history stack, such as when
21 * a link is clicked and a new page loads. When this happens, all subsequent
22 * entries in the stack are lost.
23 */
24 Push = "PUSH",
25 /**
26 * A REPLACE indicates the entry at the current index in the history stack
27 * being replaced by a new one.
28 */
29 Replace = "REPLACE"
30}
31/**
32 * The pathname, search, and hash values of a URL.
33 */
34interface Path {
35 /**
36 * A URL pathname, beginning with a /.
37 */
38 pathname: string;
39 /**
40 * A URL search string, beginning with a ?.
41 */
42 search: string;
43 /**
44 * A URL fragment identifier, beginning with a #.
45 */
46 hash: string;
47}
48/**
49 * An entry in a history stack. A location contains information about the
50 * URL path, as well as possibly some arbitrary state and a key.
51 */
52interface Location<State = any> extends Path {
53 /**
54 * A value of arbitrary data associated with this location.
55 */
56 state: State;
57 /**
58 * A unique string associated with this location. May be used to safely store
59 * and retrieve data in some other storage API, like `localStorage`.
60 *
61 * Note: This value is always "default" on the initial location.
62 */
63 key: string;
64}
65/**
66 * A change to the current location.
67 */
68interface Update {
69 /**
70 * The action that triggered the change.
71 */
72 action: Action;
73 /**
74 * The new location.
75 */
76 location: Location;
77 /**
78 * The delta between this location and the former location in the history stack
79 */
80 delta: number | null;
81}
82/**
83 * A function that receives notifications about location changes.
84 */
85interface Listener {
86 (update: Update): void;
87}
88/**
89 * Describes a location that is the destination of some navigation used in
90 * {@link Link}, {@link useNavigate}, etc.
91 */
92type To = string | Partial<Path>;
93/**
94 * A history is an interface to the navigation stack. The history serves as the
95 * source of truth for the current location, as well as provides a set of
96 * methods that may be used to change it.
97 *
98 * It is similar to the DOM's `window.history` object, but with a smaller, more
99 * focused API.
100 */
101interface History {
102 /**
103 * The last action that modified the current location. This will always be
104 * Action.Pop when a history instance is first created. This value is mutable.
105 */
106 readonly action: Action;
107 /**
108 * The current location. This value is mutable.
109 */
110 readonly location: Location;
111 /**
112 * Returns a valid href for the given `to` value that may be used as
113 * the value of an <a href> attribute.
114 *
115 * @param to - The destination URL
116 */
117 createHref(to: To): string;
118 /**
119 * Returns a URL for the given `to` value
120 *
121 * @param to - The destination URL
122 */
123 createURL(to: To): URL;
124 /**
125 * Encode a location the same way window.history would do (no-op for memory
126 * history) so we ensure our PUSH/REPLACE navigations for data routers
127 * behave the same as POP
128 *
129 * @param to Unencoded path
130 */
131 encodeLocation(to: To): Path;
132 /**
133 * Pushes a new location onto the history stack, increasing its length by one.
134 * If there were any entries in the stack after the current one, they are
135 * lost.
136 *
137 * @param to - The new URL
138 * @param state - Data to associate with the new location
139 */
140 push(to: To, state?: any): void;
141 /**
142 * Replaces the current location in the history stack with a new one. The
143 * location that was replaced will no longer be available.
144 *
145 * @param to - The new URL
146 * @param state - Data to associate with the new location
147 */
148 replace(to: To, state?: any): void;
149 /**
150 * Navigates `n` entries backward/forward in the history stack relative to the
151 * current index. For example, a "back" navigation would use go(-1).
152 *
153 * @param delta - The delta in the stack index
154 */
155 go(delta: number): void;
156 /**
157 * Sets up a listener that will be called whenever the current location
158 * changes.
159 *
160 * @param listener - A function that will be called when the location changes
161 * @returns unlisten - A function that may be used to stop listening
162 */
163 listen(listener: Listener): () => void;
164}
165
166/**
167 * An augmentable interface users can modify in their app-code to opt into
168 * future-flag-specific types
169 */
170interface Future {
171}
172type MiddlewareEnabled = Future extends {
173 unstable_middleware: infer T extends boolean;
174} ? T : false;
175
176type MaybePromise<T> = T | Promise<T>;
177/**
178 * Map of routeId -> data returned from a loader/action/error
179 */
180interface RouteData {
181 [routeId: string]: any;
182}
183type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
184type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
185/**
186 * Users can specify either lowercase or uppercase form methods on `<Form>`,
187 * useSubmit(), `<fetcher.Form>`, etc.
188 */
189type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
190/**
191 * Active navigation/fetcher form methods are exposed in uppercase on the
192 * RouterState. This is to align with the normalization done via fetch().
193 */
194type FormMethod = UpperCaseFormMethod;
195type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
196type JsonObject = {
197 [Key in string]: JsonValue;
198} & {
199 [Key in string]?: JsonValue | undefined;
200};
201type JsonArray = JsonValue[] | readonly JsonValue[];
202type JsonPrimitive = string | number | boolean | null;
203type JsonValue = JsonPrimitive | JsonObject | JsonArray;
204/**
205 * @private
206 * Internal interface to pass around for action submissions, not intended for
207 * external consumption
208 */
209type Submission = {
210 formMethod: FormMethod;
211 formAction: string;
212 formEncType: FormEncType;
213 formData: FormData;
214 json: undefined;
215 text: undefined;
216} | {
217 formMethod: FormMethod;
218 formAction: string;
219 formEncType: FormEncType;
220 formData: undefined;
221 json: JsonValue;
222 text: undefined;
223} | {
224 formMethod: FormMethod;
225 formAction: string;
226 formEncType: FormEncType;
227 formData: undefined;
228 json: undefined;
229 text: string;
230};
231interface unstable_RouterContext<T = unknown> {
232 defaultValue?: T;
233}
234/**
235 * Creates a context object that may be used to store and retrieve arbitrary values.
236 *
237 * If a `defaultValue` is provided, it will be returned from `context.get()` when no value has been
238 * set for the context. Otherwise reading this context when no value has been set will throw an
239 * error.
240 *
241 * @param defaultValue The default value for the context
242 * @returns A context object
243 */
244declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
245/**
246 * A Map of RouterContext objects to their initial values - used to populate a
247 * fresh `context` value per request/navigation/fetch
248 */
249type unstable_InitialContext = Map<unstable_RouterContext, unknown>;
250/**
251 * Provides methods for writing/reading values in application context in a typesafe way.
252 */
253declare class unstable_RouterContextProvider {
254 #private;
255 constructor(init?: unstable_InitialContext);
256 get<T>(context: unstable_RouterContext<T>): T;
257 set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
258}
259type DefaultContext = MiddlewareEnabled extends true ? unstable_RouterContextProvider : any;
260/**
261 * @private
262 * Arguments passed to route loader/action functions. Same for now but we keep
263 * this as a private implementation detail in case they diverge in the future.
264 */
265interface DataFunctionArgs<Context> {
266 /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read headers (like cookies, and {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams URLSearchParams} from the request. */
267 request: Request;
268 /**
269 * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
270 * @example
271 * // app/routes.ts
272 * route("teams/:teamId", "./team.tsx"),
273 *
274 * // app/team.tsx
275 * export function loader({
276 * params,
277 * }: Route.LoaderArgs) {
278 * params.teamId;
279 * // ^ string
280 * }
281 **/
282 params: Params;
283 /**
284 * This is the context passed in to your server adapter's getLoadContext() function.
285 * It's a way to bridge the gap between the adapter's request/response API with your React Router app.
286 * It is only applicable if you are using a custom server adapter.
287 */
288 context: Context;
289}
290/**
291 * Route middleware `next` function to call downstream handlers and then complete
292 * middlewares from the bottom-up
293 */
294interface unstable_MiddlewareNextFunction<Result = unknown> {
295 (): MaybePromise<Result>;
296}
297/**
298 * Route middleware function signature. Receives the same "data" arguments as a
299 * `loader`/`action` (`request`, `params`, `context`) as the first parameter and
300 * a `next` function as the second parameter which will call downstream handlers
301 * and then complete middlewares from the bottom-up
302 */
303type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<unstable_RouterContextProvider>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
304/**
305 * Arguments passed to loader functions
306 */
307interface LoaderFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
308}
309/**
310 * Arguments passed to action functions
311 */
312interface ActionFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
313}
314/**
315 * Loaders and actions can return anything
316 */
317type DataFunctionValue = unknown;
318type DataFunctionReturnValue = MaybePromise<DataFunctionValue>;
319/**
320 * Route loader function signature
321 */
322type LoaderFunction<Context = DefaultContext> = {
323 (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
324} & {
325 hydrate?: boolean;
326};
327/**
328 * Route action function signature
329 */
330interface ActionFunction<Context = DefaultContext> {
331 (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
332}
333/**
334 * Arguments passed to shouldRevalidate function
335 */
336interface ShouldRevalidateFunctionArgs {
337 /** This is the url the navigation started from. You can compare it with `nextUrl` to decide if you need to revalidate this route's data. */
338 currentUrl: URL;
339 /** These are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the URL that can be compared to the `nextParams` to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed. */
340 currentParams: AgnosticDataRouteMatch["params"];
341 /** In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl. */
342 nextUrl: URL;
343 /** In the case of navigation, these are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams. */
344 nextParams: AgnosticDataRouteMatch["params"];
345 /** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
346 formMethod?: Submission["formMethod"];
347 /** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
348 formAction?: Submission["formAction"];
349 /** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
350 formEncType?: Submission["formEncType"];
351 /** The form submission data when the form's encType is `text/plain` */
352 text?: Submission["text"];
353 /** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
354 formData?: Submission["formData"];
355 /** The form submission data when the form's encType is `application/json` */
356 json?: Submission["json"];
357 /** The status code of the action response */
358 actionStatus?: number;
359 /**
360 * When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.
361 *
362 * @example
363 * export async function action() {
364 * await saveSomeStuff();
365 * return { ok: true };
366 * }
367 *
368 * export function shouldRevalidate({
369 * actionResult,
370 * }) {
371 * if (actionResult?.ok) {
372 * return false;
373 * }
374 * return true;
375 * }
376 */
377 actionResult?: any;
378 /**
379 * By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:
380 *
381 * /projects/123/tasks/abc
382 * /projects/123/tasks/def
383 * React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
384 *
385 * It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.
386 */
387 defaultShouldRevalidate: boolean;
388}
389/**
390 * Route shouldRevalidate function signature. This runs after any submission
391 * (navigation or fetcher), so we flatten the navigation/fetcher submission
392 * onto the arguments. It shouldn't matter whether it came from a navigation
393 * or a fetcher, what really matters is the URLs and the formData since loaders
394 * have to re-run based on the data models that were potentially mutated.
395 */
396interface ShouldRevalidateFunction {
397 (args: ShouldRevalidateFunctionArgs): boolean;
398}
399interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
400 /**
401 * @private
402 */
403 _lazyPromises?: {
404 middleware: Promise<void> | undefined;
405 handler: Promise<void> | undefined;
406 route: Promise<void> | undefined;
407 };
408 /**
409 * A boolean value indicating whether this route handler should be called in this pass.
410 *
411 * The `matches` array always includes _all_ matched routes even when only _some_
412 * route handlers need to be called so that things like middleware can be implemented.
413 *
414 * `shouldLoad` is usually only interesting if you are skipping the route handler
415 * entirely and implementing custom handler logic - since it lets you determine
416 * if that custom logic should run for this route or not.
417 *
418 * For example:
419 * - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
420 * you'll get an array of three matches (`[parent, child, b]`), but only `b`
421 * will have `shouldLoad=true` because the data for `parent` and `child` is
422 * already loaded
423 * - If you are on `/parent/child/a` and you submit to `a`'s `action`, then only
424 * `a` will have `shouldLoad=true` for the action execution of `dataStrategy`
425 * - After the `action`, `dataStrategy` will be called again for the `loader`
426 * revalidation, and all matches will have `shouldLoad=true` (assuming no custom
427 * `shouldRevalidate` implementations)
428 */
429 shouldLoad: boolean;
430 unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
431 unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
432 /**
433 * An async function that will resolve any `route.lazy` implementations and
434 * execute the route's handler (if necessary), returning a `DataStrategyResult`
435 *
436 * - Calling `match.resolve` does not mean you're calling the `loader`/`action`
437 * (the "handler") - `resolve` will only call the `handler` internally if
438 * needed _and_ if you don't pass your own `handlerOverride` function parameter
439 * - It is safe to call `match.resolve` for all matches, even if they have
440 * `shouldLoad=false`, and it will no-op if no loading is required
441 * - You should generally always call `match.resolve()` for `shouldLoad:true`
442 * routes to ensure that any `route.lazy` implementations are processed
443 * - See the examples below for how to implement custom handler execution via
444 * `match.resolve`
445 */
446 resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
447}
448interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
449 /**
450 * Matches for this route extended with Data strategy APIs
451 */
452 matches: DataStrategyMatch[];
453 unstable_runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
454 /**
455 * The key of the fetcher we are calling `dataStrategy` for, otherwise `null`
456 * for navigational executions
457 */
458 fetcherKey: string | null;
459}
460/**
461 * Result from a loader or action called via dataStrategy
462 */
463interface DataStrategyResult {
464 type: "data" | "error";
465 result: unknown;
466}
467interface DataStrategyFunction<Context = DefaultContext> {
468 (args: DataStrategyFunctionArgs<Context>): Promise<Record<string, DataStrategyResult>>;
469}
470type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
471 signal: AbortSignal;
472 path: string;
473 matches: M[];
474 fetcherKey: string | undefined;
475 patch: (routeId: string | null, children: O[]) => void;
476};
477type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => MaybePromise<void>;
478/**
479 * Function provided by the framework-aware layers to set any framework-specific
480 * properties from framework-agnostic properties
481 */
482interface MapRoutePropertiesFunction {
483 (route: AgnosticRouteObject): {
484 hasErrorBoundary: boolean;
485 } & Record<string, any>;
486}
487/**
488 * Keys we cannot change from within a lazy object. We spread all other keys
489 * onto the route. Either they're meaningful to the router, or they'll get
490 * ignored.
491 */
492type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
493/**
494 * Keys we cannot change from within a lazy() function. We spread all other keys
495 * onto the route. Either they're meaningful to the router, or they'll get
496 * ignored.
497 */
498type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "unstable_middleware";
499/**
500 * lazy object to load route properties, which can add non-matching
501 * related properties to a route
502 */
503type LazyRouteObject<R extends AgnosticRouteObject> = {
504 [K in keyof R as K extends UnsupportedLazyRouteObjectKey ? never : K]?: () => Promise<R[K] | null | undefined>;
505};
506/**
507 * lazy() function to load a route definition, which can add non-matching
508 * related properties to a route
509 */
510interface LazyRouteFunction<R extends AgnosticRouteObject> {
511 (): Promise<Omit<R, UnsupportedLazyRouteFunctionKey> & Partial<Record<UnsupportedLazyRouteFunctionKey, never>>>;
512}
513type LazyRouteDefinition<R extends AgnosticRouteObject> = LazyRouteObject<R> | LazyRouteFunction<R>;
514/**
515 * Base RouteObject with common props shared by all types of routes
516 */
517type AgnosticBaseRouteObject = {
518 caseSensitive?: boolean;
519 path?: string;
520 id?: string;
521 unstable_middleware?: unstable_MiddlewareFunction[];
522 loader?: LoaderFunction | boolean;
523 action?: ActionFunction | boolean;
524 hasErrorBoundary?: boolean;
525 shouldRevalidate?: ShouldRevalidateFunction;
526 handle?: any;
527 lazy?: LazyRouteDefinition<AgnosticBaseRouteObject>;
528};
529/**
530 * Index routes must not have children
531 */
532type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
533 children?: undefined;
534 index: true;
535};
536/**
537 * Non-index routes may have children, but cannot have index
538 */
539type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
540 children?: AgnosticRouteObject[];
541 index?: false;
542};
543/**
544 * A route object represents a logical route, with (optionally) its child
545 * routes organized in a tree-like structure.
546 */
547type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
548type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
549 id: string;
550};
551type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
552 children?: AgnosticDataRouteObject[];
553 id: string;
554};
555/**
556 * A data route object, which is just a RouteObject with a required unique ID
557 */
558type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
559/**
560 * The parameters that were parsed from the URL path.
561 */
562type Params<Key extends string = string> = {
563 readonly [key in Key]: string | undefined;
564};
565/**
566 * A RouteMatch contains info about how a route matched a URL.
567 */
568interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
569 /**
570 * The names and values of dynamic parameters in the URL.
571 */
572 params: Params<ParamKey>;
573 /**
574 * The portion of the URL pathname that was matched.
575 */
576 pathname: string;
577 /**
578 * The portion of the URL pathname that was matched before child routes.
579 */
580 pathnameBase: string;
581 /**
582 * The route object that was used to match.
583 */
584 route: RouteObjectType;
585}
586interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
587}
588/**
589 * Matches the given routes to a location and returns the match data.
590 *
591 * @category Utils
592 */
593declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
594interface UIMatch<Data = unknown, Handle = unknown> {
595 id: string;
596 pathname: string;
597 /**
598 * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
599 **/
600 params: AgnosticRouteMatch["params"];
601 /** The return value from the matched route's loader or clientLoader */
602 data: Data;
603 /** The {@link https://reactrouter.com/start/framework/route-module#handle handle object} exported from the matched route module */
604 handle: Handle;
605}
606declare class DataWithResponseInit<D> {
607 type: string;
608 data: D;
609 init: ResponseInit | null;
610 constructor(data: D, init?: ResponseInit);
611}
612/**
613 * Create "responses" that contain `status`/`headers` without forcing
614 * serialization into an actual `Response` - used by Remix single fetch
615 *
616 * @category Utils
617 */
618declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
619type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
620/**
621 * A redirect response. Sets the status code and the `Location` header.
622 * Defaults to "302 Found".
623 *
624 * @category Utils
625 */
626declare const redirect$1: RedirectFunction;
627/**
628 * A redirect response that will force a document reload to the new location.
629 * Sets the status code and the `Location` header.
630 * Defaults to "302 Found".
631 *
632 * @category Utils
633 */
634declare const redirectDocument$1: RedirectFunction;
635/**
636 * A redirect response that will perform a `history.replaceState` instead of a
637 * `history.pushState` for client-side navigation redirects.
638 * Sets the status code and the `Location` header.
639 * Defaults to "302 Found".
640 *
641 * @category Utils
642 */
643declare const replace$1: RedirectFunction;
644
645/**
646 * A Router instance manages all navigation and data loading/mutations
647 */
648interface Router {
649 /**
650 * @private
651 * PRIVATE - DO NOT USE
652 *
653 * Return the basename for the router
654 */
655 get basename(): RouterInit["basename"];
656 /**
657 * @private
658 * PRIVATE - DO NOT USE
659 *
660 * Return the future config for the router
661 */
662 get future(): FutureConfig;
663 /**
664 * @private
665 * PRIVATE - DO NOT USE
666 *
667 * Return the current state of the router
668 */
669 get state(): RouterState;
670 /**
671 * @private
672 * PRIVATE - DO NOT USE
673 *
674 * Return the routes for this router instance
675 */
676 get routes(): AgnosticDataRouteObject[];
677 /**
678 * @private
679 * PRIVATE - DO NOT USE
680 *
681 * Return the window associated with the router
682 */
683 get window(): RouterInit["window"];
684 /**
685 * @private
686 * PRIVATE - DO NOT USE
687 *
688 * Initialize the router, including adding history listeners and kicking off
689 * initial data fetches. Returns a function to cleanup listeners and abort
690 * any in-progress loads
691 */
692 initialize(): Router;
693 /**
694 * @private
695 * PRIVATE - DO NOT USE
696 *
697 * Subscribe to router.state updates
698 *
699 * @param fn function to call with the new state
700 */
701 subscribe(fn: RouterSubscriber): () => void;
702 /**
703 * @private
704 * PRIVATE - DO NOT USE
705 *
706 * Enable scroll restoration behavior in the router
707 *
708 * @param savedScrollPositions Object that will manage positions, in case
709 * it's being restored from sessionStorage
710 * @param getScrollPosition Function to get the active Y scroll position
711 * @param getKey Function to get the key to use for restoration
712 */
713 enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
714 /**
715 * @private
716 * PRIVATE - DO NOT USE
717 *
718 * Navigate forward/backward in the history stack
719 * @param to Delta to move in the history stack
720 */
721 navigate(to: number): Promise<void>;
722 /**
723 * Navigate to the given path
724 * @param to Path to navigate to
725 * @param opts Navigation options (method, submission, etc.)
726 */
727 navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
728 /**
729 * @private
730 * PRIVATE - DO NOT USE
731 *
732 * Trigger a fetcher load/submission
733 *
734 * @param key Fetcher key
735 * @param routeId Route that owns the fetcher
736 * @param href href to fetch
737 * @param opts Fetcher options, (method, submission, etc.)
738 */
739 fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
740 /**
741 * @private
742 * PRIVATE - DO NOT USE
743 *
744 * Trigger a revalidation of all current route loaders and fetcher loads
745 */
746 revalidate(): Promise<void>;
747 /**
748 * @private
749 * PRIVATE - DO NOT USE
750 *
751 * Utility function to create an href for the given location
752 * @param location
753 */
754 createHref(location: Location | URL): string;
755 /**
756 * @private
757 * PRIVATE - DO NOT USE
758 *
759 * Utility function to URL encode a destination path according to the internal
760 * history implementation
761 * @param to
762 */
763 encodeLocation(to: To): Path;
764 /**
765 * @private
766 * PRIVATE - DO NOT USE
767 *
768 * Get/create a fetcher for the given key
769 * @param key
770 */
771 getFetcher<TData = any>(key: string): Fetcher<TData>;
772 /**
773 * @private
774 * PRIVATE - DO NOT USE
775 *
776 * Delete the fetcher for a given key
777 * @param key
778 */
779 deleteFetcher(key: string): void;
780 /**
781 * @private
782 * PRIVATE - DO NOT USE
783 *
784 * Cleanup listeners and abort any in-progress loads
785 */
786 dispose(): void;
787 /**
788 * @private
789 * PRIVATE - DO NOT USE
790 *
791 * Get a navigation blocker
792 * @param key The identifier for the blocker
793 * @param fn The blocker function implementation
794 */
795 getBlocker(key: string, fn: BlockerFunction): Blocker;
796 /**
797 * @private
798 * PRIVATE - DO NOT USE
799 *
800 * Delete a navigation blocker
801 * @param key The identifier for the blocker
802 */
803 deleteBlocker(key: string): void;
804 /**
805 * @private
806 * PRIVATE DO NOT USE
807 *
808 * Patch additional children routes into an existing parent route
809 * @param routeId The parent route id or a callback function accepting `patch`
810 * to perform batch patching
811 * @param children The additional children routes
812 * @param unstable_allowElementMutations Allow mutation or route elements on
813 * existing routes. Intended for RSC-usage
814 * only.
815 */
816 patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
817 /**
818 * @private
819 * PRIVATE - DO NOT USE
820 *
821 * HMR needs to pass in-flight route updates to React Router
822 * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
823 */
824 _internalSetRoutes(routes: AgnosticRouteObject[]): void;
825 /**
826 * @private
827 * PRIVATE - DO NOT USE
828 *
829 * Cause subscribers to re-render. This is used to force a re-render.
830 */
831 _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
832 /**
833 * @private
834 * PRIVATE - DO NOT USE
835 *
836 * Internal fetch AbortControllers accessed by unit tests
837 */
838 _internalFetchControllers: Map<string, AbortController>;
839}
840/**
841 * State maintained internally by the router. During a navigation, all states
842 * reflect the "old" location unless otherwise noted.
843 */
844interface RouterState {
845 /**
846 * The action of the most recent navigation
847 */
848 historyAction: Action;
849 /**
850 * The current location reflected by the router
851 */
852 location: Location;
853 /**
854 * The current set of route matches
855 */
856 matches: AgnosticDataRouteMatch[];
857 /**
858 * Tracks whether we've completed our initial data load
859 */
860 initialized: boolean;
861 /**
862 * Current scroll position we should start at for a new view
863 * - number -> scroll position to restore to
864 * - false -> do not restore scroll at all (used during submissions/revalidations)
865 * - null -> don't have a saved position, scroll to hash or top of page
866 */
867 restoreScrollPosition: number | false | null;
868 /**
869 * Indicate whether this navigation should skip resetting the scroll position
870 * if we are unable to restore the scroll position
871 */
872 preventScrollReset: boolean;
873 /**
874 * Tracks the state of the current navigation
875 */
876 navigation: Navigation;
877 /**
878 * Tracks any in-progress revalidations
879 */
880 revalidation: RevalidationState;
881 /**
882 * Data from the loaders for the current matches
883 */
884 loaderData: RouteData;
885 /**
886 * Data from the action for the current matches
887 */
888 actionData: RouteData | null;
889 /**
890 * Errors caught from loaders for the current matches
891 */
892 errors: RouteData | null;
893 /**
894 * Map of current fetchers
895 */
896 fetchers: Map<string, Fetcher>;
897 /**
898 * Map of current blockers
899 */
900 blockers: Map<string, Blocker>;
901}
902/**
903 * Data that can be passed into hydrate a Router from SSR
904 */
905type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
906/**
907 * Future flags to toggle new feature behavior
908 */
909interface FutureConfig {
910 unstable_middleware: boolean;
911}
912/**
913 * Initialization options for createRouter
914 */
915interface RouterInit {
916 routes: AgnosticRouteObject[];
917 history: History;
918 basename?: string;
919 unstable_getContext?: () => MaybePromise<unstable_InitialContext>;
920 mapRouteProperties?: MapRoutePropertiesFunction;
921 future?: Partial<FutureConfig>;
922 hydrationRouteProperties?: string[];
923 hydrationData?: HydrationState;
924 window?: Window;
925 dataStrategy?: DataStrategyFunction;
926 patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
927}
928/**
929 * State returned from a server-side query() call
930 */
931interface StaticHandlerContext {
932 basename: Router["basename"];
933 location: RouterState["location"];
934 matches: RouterState["matches"];
935 loaderData: RouterState["loaderData"];
936 actionData: RouterState["actionData"];
937 errors: RouterState["errors"];
938 statusCode: number;
939 loaderHeaders: Record<string, Headers>;
940 actionHeaders: Record<string, Headers>;
941 _deepestRenderedBoundaryId?: string | null;
942}
943/**
944 * A StaticHandler instance manages a singular SSR navigation/fetch event
945 */
946interface StaticHandler {
947 dataRoutes: AgnosticDataRouteObject[];
948 query(request: Request, opts?: {
949 requestContext?: unknown;
950 filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
951 skipLoaderErrorBubbling?: boolean;
952 skipRevalidation?: boolean;
953 dataStrategy?: DataStrategyFunction<unknown>;
954 unstable_respond?: (staticContext: StaticHandlerContext) => MaybePromise<Response>;
955 unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
956 }): Promise<StaticHandlerContext | Response>;
957 queryRoute(request: Request, opts?: {
958 routeId?: string;
959 requestContext?: unknown;
960 dataStrategy?: DataStrategyFunction<unknown>;
961 unstable_respond?: (res: Response) => MaybePromise<Response>;
962 }): Promise<any>;
963}
964type ViewTransitionOpts = {
965 currentLocation: Location;
966 nextLocation: Location;
967};
968/**
969 * Subscriber function signature for changes to router state
970 */
971interface RouterSubscriber {
972 (state: RouterState, opts: {
973 deletedFetchers: string[];
974 viewTransitionOpts?: ViewTransitionOpts;
975 flushSync: boolean;
976 }): void;
977}
978/**
979 * Function signature for determining the key to be used in scroll restoration
980 * for a given location
981 */
982interface GetScrollRestorationKeyFunction {
983 (location: Location, matches: UIMatch[]): string | null;
984}
985/**
986 * Function signature for determining the current scroll position
987 */
988interface GetScrollPositionFunction {
989 (): number;
990}
991/**
992 * - "route": relative to the route hierarchy so `..` means remove all segments
993 * of the current route even if it has many. For example, a `route("posts/:id")`
994 * would have both `:id` and `posts` removed from the url.
995 * - "path": relative to the pathname so `..` means remove one segment of the
996 * pathname. For example, a `route("posts/:id")` would have only `:id` removed
997 * from the url.
998 */
999type RelativeRoutingType = "route" | "path";
1000type BaseNavigateOrFetchOptions = {
1001 preventScrollReset?: boolean;
1002 relative?: RelativeRoutingType;
1003 flushSync?: boolean;
1004};
1005type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
1006 replace?: boolean;
1007 state?: any;
1008 fromRouteId?: string;
1009 viewTransition?: boolean;
1010};
1011type BaseSubmissionOptions = {
1012 formMethod?: HTMLFormMethod;
1013 formEncType?: FormEncType;
1014} & ({
1015 formData: FormData;
1016 body?: undefined;
1017} | {
1018 formData?: undefined;
1019 body: any;
1020});
1021/**
1022 * Options for a navigate() call for a normal (non-submission) navigation
1023 */
1024type LinkNavigateOptions = BaseNavigateOptions;
1025/**
1026 * Options for a navigate() call for a submission navigation
1027 */
1028type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
1029/**
1030 * Options to pass to navigate() for a navigation
1031 */
1032type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
1033/**
1034 * Options for a fetch() load
1035 */
1036type LoadFetchOptions = BaseNavigateOrFetchOptions;
1037/**
1038 * Options for a fetch() submission
1039 */
1040type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
1041/**
1042 * Options to pass to fetch()
1043 */
1044type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
1045/**
1046 * Potential states for state.navigation
1047 */
1048type NavigationStates = {
1049 Idle: {
1050 state: "idle";
1051 location: undefined;
1052 formMethod: undefined;
1053 formAction: undefined;
1054 formEncType: undefined;
1055 formData: undefined;
1056 json: undefined;
1057 text: undefined;
1058 };
1059 Loading: {
1060 state: "loading";
1061 location: Location;
1062 formMethod: Submission["formMethod"] | undefined;
1063 formAction: Submission["formAction"] | undefined;
1064 formEncType: Submission["formEncType"] | undefined;
1065 formData: Submission["formData"] | undefined;
1066 json: Submission["json"] | undefined;
1067 text: Submission["text"] | undefined;
1068 };
1069 Submitting: {
1070 state: "submitting";
1071 location: Location;
1072 formMethod: Submission["formMethod"];
1073 formAction: Submission["formAction"];
1074 formEncType: Submission["formEncType"];
1075 formData: Submission["formData"];
1076 json: Submission["json"];
1077 text: Submission["text"];
1078 };
1079};
1080type Navigation = NavigationStates[keyof NavigationStates];
1081type RevalidationState = "idle" | "loading";
1082/**
1083 * Potential states for fetchers
1084 */
1085type FetcherStates<TData = any> = {
1086 /**
1087 * The fetcher is not calling a loader or action
1088 *
1089 * ```tsx
1090 * fetcher.state === "idle"
1091 * ```
1092 */
1093 Idle: {
1094 state: "idle";
1095 formMethod: undefined;
1096 formAction: undefined;
1097 formEncType: undefined;
1098 text: undefined;
1099 formData: undefined;
1100 json: undefined;
1101 /**
1102 * If the fetcher has never been called, this will be undefined.
1103 */
1104 data: TData | undefined;
1105 };
1106 /**
1107 * The fetcher is loading data from a {@link LoaderFunction | loader} from a
1108 * call to {@link FetcherWithComponents.load | `fetcher.load`}.
1109 *
1110 * ```tsx
1111 * // somewhere
1112 * <button onClick={() => fetcher.load("/some/route") }>Load</button>
1113 *
1114 * // the state will update
1115 * fetcher.state === "loading"
1116 * ```
1117 */
1118 Loading: {
1119 state: "loading";
1120 formMethod: Submission["formMethod"] | undefined;
1121 formAction: Submission["formAction"] | undefined;
1122 formEncType: Submission["formEncType"] | undefined;
1123 text: Submission["text"] | undefined;
1124 formData: Submission["formData"] | undefined;
1125 json: Submission["json"] | undefined;
1126 data: TData | undefined;
1127 };
1128 /**
1129 The fetcher is submitting to a {@link LoaderFunction} (GET) or {@link ActionFunction} (POST) from a {@link FetcherWithComponents.Form | `fetcher.Form`} or {@link FetcherWithComponents.submit | `fetcher.submit`}.
1130
1131 ```tsx
1132 // somewhere
1133 <input
1134 onChange={e => {
1135 fetcher.submit(event.currentTarget.form, { method: "post" });
1136 }}
1137 />
1138
1139 // the state will update
1140 fetcher.state === "submitting"
1141
1142 // and formData will be available
1143 fetcher.formData
1144 ```
1145 */
1146 Submitting: {
1147 state: "submitting";
1148 formMethod: Submission["formMethod"];
1149 formAction: Submission["formAction"];
1150 formEncType: Submission["formEncType"];
1151 text: Submission["text"];
1152 formData: Submission["formData"];
1153 json: Submission["json"];
1154 data: TData | undefined;
1155 };
1156};
1157type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
1158interface BlockerBlocked {
1159 state: "blocked";
1160 reset: () => void;
1161 proceed: () => void;
1162 location: Location;
1163}
1164interface BlockerUnblocked {
1165 state: "unblocked";
1166 reset: undefined;
1167 proceed: undefined;
1168 location: undefined;
1169}
1170interface BlockerProceeding {
1171 state: "proceeding";
1172 reset: undefined;
1173 proceed: undefined;
1174 location: Location;
1175}
1176type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1177type BlockerFunction = (args: {
1178 currentLocation: Location;
1179 nextLocation: Location;
1180 historyAction: Action;
1181}) => boolean;
1182interface CreateStaticHandlerOptions {
1183 basename?: string;
1184 mapRouteProperties?: MapRoutePropertiesFunction;
1185 future?: {};
1186}
1187declare function createStaticHandler(routes: AgnosticRouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
1188
1189interface IndexRouteObject {
1190 caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
1191 path?: AgnosticIndexRouteObject["path"];
1192 id?: AgnosticIndexRouteObject["id"];
1193 unstable_middleware?: AgnosticIndexRouteObject["unstable_middleware"];
1194 loader?: AgnosticIndexRouteObject["loader"];
1195 action?: AgnosticIndexRouteObject["action"];
1196 hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
1197 shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
1198 handle?: AgnosticIndexRouteObject["handle"];
1199 index: true;
1200 children?: undefined;
1201 element?: React.ReactNode | null;
1202 hydrateFallbackElement?: React.ReactNode | null;
1203 errorElement?: React.ReactNode | null;
1204 Component?: React.ComponentType | null;
1205 HydrateFallback?: React.ComponentType | null;
1206 ErrorBoundary?: React.ComponentType | null;
1207 lazy?: LazyRouteDefinition<RouteObject>;
1208}
1209interface NonIndexRouteObject {
1210 caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
1211 path?: AgnosticNonIndexRouteObject["path"];
1212 id?: AgnosticNonIndexRouteObject["id"];
1213 unstable_middleware?: AgnosticNonIndexRouteObject["unstable_middleware"];
1214 loader?: AgnosticNonIndexRouteObject["loader"];
1215 action?: AgnosticNonIndexRouteObject["action"];
1216 hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
1217 shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
1218 handle?: AgnosticNonIndexRouteObject["handle"];
1219 index?: false;
1220 children?: RouteObject[];
1221 element?: React.ReactNode | null;
1222 hydrateFallbackElement?: React.ReactNode | null;
1223 errorElement?: React.ReactNode | null;
1224 Component?: React.ComponentType | null;
1225 HydrateFallback?: React.ComponentType | null;
1226 ErrorBoundary?: React.ComponentType | null;
1227 lazy?: LazyRouteDefinition<RouteObject>;
1228}
1229type RouteObject = IndexRouteObject | NonIndexRouteObject;
1230type DataRouteObject = RouteObject & {
1231 children?: DataRouteObject[];
1232 id: string;
1233};
1234interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
1235}
1236interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
1237}
1238
1239type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1240type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1241interface HtmlLinkProps {
1242 /**
1243 * Address of the hyperlink
1244 */
1245 href?: string;
1246 /**
1247 * How the element handles crossorigin requests
1248 */
1249 crossOrigin?: "anonymous" | "use-credentials";
1250 /**
1251 * Relationship between the document containing the hyperlink and the destination resource
1252 */
1253 rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
1254 /**
1255 * Applicable media: "screen", "print", "(max-width: 764px)"
1256 */
1257 media?: string;
1258 /**
1259 * Integrity metadata used in Subresource Integrity checks
1260 */
1261 integrity?: string;
1262 /**
1263 * Language of the linked resource
1264 */
1265 hrefLang?: string;
1266 /**
1267 * Hint for the type of the referenced resource
1268 */
1269 type?: string;
1270 /**
1271 * Referrer policy for fetches initiated by the element
1272 */
1273 referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
1274 /**
1275 * Sizes of the icons (for rel="icon")
1276 */
1277 sizes?: string;
1278 /**
1279 * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1280 */
1281 as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
1282 /**
1283 * Color to use when customizing a site's icon (for rel="mask-icon")
1284 */
1285 color?: string;
1286 /**
1287 * Whether the link is disabled
1288 */
1289 disabled?: boolean;
1290 /**
1291 * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
1292 */
1293 title?: string;
1294 /**
1295 * Images to use in different situations, e.g., high-resolution displays,
1296 * small monitors, etc. (for rel="preload")
1297 */
1298 imageSrcSet?: string;
1299 /**
1300 * Image sizes for different page layouts (for rel="preload")
1301 */
1302 imageSizes?: string;
1303}
1304interface HtmlLinkPreloadImage extends HtmlLinkProps {
1305 /**
1306 * Relationship between the document containing the hyperlink and the destination resource
1307 */
1308 rel: "preload";
1309 /**
1310 * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1311 */
1312 as: "image";
1313 /**
1314 * Address of the hyperlink
1315 */
1316 href?: string;
1317 /**
1318 * Images to use in different situations, e.g., high-resolution displays,
1319 * small monitors, etc. (for rel="preload")
1320 */
1321 imageSrcSet: string;
1322 /**
1323 * Image sizes for different page layouts (for rel="preload")
1324 */
1325 imageSizes?: string;
1326}
1327/**
1328 * Represents a `<link>` element.
1329 *
1330 * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
1331 */
1332type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
1333 imageSizes?: never;
1334});
1335interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1336 /**
1337 * The absolute path of the page to prefetch.
1338 */
1339 page: string;
1340}
1341type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1342
1343type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1344 [key: PropertyKey]: Serializable;
1345} | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
1346
1347type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
1348type IsAny<T> = 0 extends 1 & T ? true : false;
1349type Func = (...args: any[]) => unknown;
1350
1351/**
1352 * A brand that can be applied to a type to indicate that it will serialize
1353 * to a specific type when transported to the client from a loader.
1354 * Only use this if you have additional serialization/deserialization logic
1355 * in your application.
1356 */
1357type unstable_SerializesTo<T> = {
1358 unstable__ReactRouter_SerializesTo: [T];
1359};
1360
1361type Serialize<T> = T extends unstable_SerializesTo<infer To> ? To : T extends Serializable ? T : T extends (...args: any[]) => unknown ? undefined : T extends Promise<infer U> ? Promise<Serialize<U>> : T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [Serialize<F>, ...Serialize<R>] : T extends Array<infer U> ? Array<Serialize<U>> : T extends readonly unknown[] ? readonly Serialize<T[number]>[] : T extends Record<any, any> ? {
1362 [K in keyof T]: Serialize<T[K]>;
1363} : undefined;
1364type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1365type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1366type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1367type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1368type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1369type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1370type ClientDataFunctionArgs<Params> = {
1371 /**
1372 * A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
1373 *
1374 * @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
1375 **/
1376 request: Request;
1377 /**
1378 * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
1379 * @example
1380 * // app/routes.ts
1381 * route("teams/:teamId", "./team.tsx"),
1382 *
1383 * // app/team.tsx
1384 * export function clientLoader({
1385 * params,
1386 * }: Route.ClientLoaderArgs) {
1387 * params.teamId;
1388 * // ^ string
1389 * }
1390 **/
1391 params: Params;
1392 /**
1393 * When `future.unstable_middleware` is not enabled, this is undefined.
1394 *
1395 * When `future.unstable_middleware` is enabled, this is an instance of
1396 * `unstable_RouterContextProvider` and can be used to access context values
1397 * from your route middlewares. You may pass in initial context values in your
1398 * `<HydratedRouter unstable_getContext>` prop
1399 */
1400 context: unstable_RouterContextProvider;
1401};
1402type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
1403 ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
1404] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1405
1406/**
1407 * A function that handles data mutations for a route on the client
1408 */
1409type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
1410/**
1411 * Arguments passed to a route `clientAction` function
1412 */
1413type ClientActionFunctionArgs = ActionFunctionArgs & {
1414 serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1415};
1416/**
1417 * A function that loads data for a route on the client
1418 */
1419type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
1420 hydrate?: boolean;
1421};
1422/**
1423 * Arguments passed to a route `clientLoader` function
1424 */
1425type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1426 serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1427};
1428type HeadersArgs = {
1429 loaderHeaders: Headers;
1430 parentHeaders: Headers;
1431 actionHeaders: Headers;
1432 errorHeaders: Headers | undefined;
1433};
1434/**
1435 * A function that returns HTTP headers to be used for a route. These headers
1436 * will be merged with (and take precedence over) headers from parent routes.
1437 */
1438interface HeadersFunction {
1439 (args: HeadersArgs): Headers | HeadersInit;
1440}
1441/**
1442 * A function that defines `<link>` tags to be inserted into the `<head>` of
1443 * the document on route transitions.
1444 *
1445 * @see https://remix.run/route/meta
1446 */
1447interface LinksFunction {
1448 (): LinkDescriptor[];
1449}
1450interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1451 id: RouteId;
1452 pathname: DataRouteMatch["pathname"];
1453 data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1454 handle?: RouteHandle;
1455 params: DataRouteMatch["params"];
1456 meta: MetaDescriptor[];
1457 error?: unknown;
1458}
1459type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
1460 [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1461}[keyof MatchLoaders]>;
1462interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1463 data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1464 params: Params;
1465 location: Location;
1466 matches: MetaMatches<MatchLoaders>;
1467 error?: unknown;
1468}
1469/**
1470 * A function that returns an array of data objects to use for rendering
1471 * metadata HTML tags in a route. These tags are not rendered on descendant
1472 * routes in the route hierarchy. In other words, they will only be rendered on
1473 * the route in which they are exported.
1474 *
1475 * @param Loader - The type of the current route's loader function
1476 * @param MatchLoaders - Mapping from a parent route's filepath to its loader
1477 * function type
1478 *
1479 * Note that parent route filepaths are relative to the `app/` directory.
1480 *
1481 * For example, if this meta function is for `/sales/customers/$customerId`:
1482 *
1483 * ```ts
1484 * // app/root.tsx
1485 * const loader = () => ({ hello: "world" })
1486 * export type Loader = typeof loader
1487 *
1488 * // app/routes/sales.tsx
1489 * const loader = () => ({ salesCount: 1074 })
1490 * export type Loader = typeof loader
1491 *
1492 * // app/routes/sales/customers.tsx
1493 * const loader = () => ({ customerCount: 74 })
1494 * export type Loader = typeof loader
1495 *
1496 * // app/routes/sales/customers/$customersId.tsx
1497 * import type { Loader as RootLoader } from "../../../root"
1498 * import type { Loader as SalesLoader } from "../../sales"
1499 * import type { Loader as CustomersLoader } from "../../sales/customers"
1500 *
1501 * const loader = () => ({ name: "Customer name" })
1502 *
1503 * const meta: MetaFunction<typeof loader, {
1504 * "root": RootLoader,
1505 * "routes/sales": SalesLoader,
1506 * "routes/sales/customers": CustomersLoader,
1507 * }> = ({ data, matches }) => {
1508 * const { name } = data
1509 * // ^? string
1510 * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
1511 * // ^? number
1512 * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
1513 * // ^? number
1514 * const { hello } = matches.find((match) => match.id === "root").data
1515 * // ^? "world"
1516 * }
1517 * ```
1518 */
1519interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1520 (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
1521}
1522type MetaDescriptor = {
1523 charSet: "utf-8";
1524} | {
1525 title: string;
1526} | {
1527 name: string;
1528 content: string;
1529} | {
1530 property: string;
1531 content: string;
1532} | {
1533 httpEquiv: string;
1534 content: string;
1535} | {
1536 "script:ld+json": LdJsonObject;
1537} | {
1538 tagName: "meta" | "link";
1539 [name: string]: string;
1540} | {
1541 [name: string]: unknown;
1542};
1543type LdJsonObject = {
1544 [Key in string]: LdJsonValue;
1545} & {
1546 [Key in string]?: LdJsonValue | undefined;
1547};
1548type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
1549type LdJsonPrimitive = string | number | boolean | null;
1550type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
1551/**
1552 * An arbitrary object that is associated with a route.
1553 *
1554 * @see https://remix.run/route/handle
1555 */
1556type RouteHandle = unknown;
1557
1558type ServerContext = {
1559 redirect?: Response;
1560};
1561declare global {
1562 var ___reactRouterServerStorage___: AsyncLocalStorage<ServerContext> | undefined;
1563}
1564declare const redirect: typeof redirect$1;
1565declare const redirectDocument: typeof redirectDocument$1;
1566declare const replace: typeof replace$1;
1567type RSCRouteConfigEntryBase = {
1568 action?: ActionFunction;
1569 clientAction?: ClientActionFunction;
1570 clientLoader?: ClientLoaderFunction;
1571 ErrorBoundary?: React.ComponentType<any>;
1572 handle?: any;
1573 headers?: HeadersFunction;
1574 HydrateFallback?: React.ComponentType<any>;
1575 Layout?: React.ComponentType<any>;
1576 links?: LinksFunction;
1577 loader?: LoaderFunction;
1578 meta?: MetaFunction;
1579 shouldRevalidate?: ShouldRevalidateFunction;
1580};
1581type RSCRouteConfigEntry = RSCRouteConfigEntryBase & {
1582 id: string;
1583 path?: string;
1584 Component?: React.ComponentType<any>;
1585 lazy?: () => Promise<RSCRouteConfigEntryBase & ({
1586 default?: React.ComponentType<any>;
1587 Component?: never;
1588 } | {
1589 default?: never;
1590 Component?: React.ComponentType<any>;
1591 })>;
1592} & ({
1593 index: true;
1594} | {
1595 children?: RSCRouteConfigEntry[];
1596});
1597type RSCRouteConfig = Array<RSCRouteConfigEntry>;
1598type RSCRouteManifest = {
1599 clientAction?: ClientActionFunction;
1600 clientLoader?: ClientLoaderFunction;
1601 element?: React.ReactElement | false;
1602 errorElement?: React.ReactElement;
1603 handle?: any;
1604 hasAction: boolean;
1605 hasComponent: boolean;
1606 hasErrorBoundary: boolean;
1607 hasLoader: boolean;
1608 hydrateFallbackElement?: React.ReactElement;
1609 id: string;
1610 index?: boolean;
1611 links?: LinksFunction;
1612 meta?: MetaFunction;
1613 parentId?: string;
1614 path?: string;
1615 shouldRevalidate?: ShouldRevalidateFunction;
1616};
1617type RSCRouteMatch = RSCRouteManifest & {
1618 params: Params;
1619 pathname: string;
1620 pathnameBase: string;
1621};
1622type RSCRenderPayload = {
1623 type: "render";
1624 actionData: Record<string, any> | null;
1625 basename: string | undefined;
1626 errors: Record<string, any> | null;
1627 loaderData: Record<string, any>;
1628 location: Location;
1629 matches: RSCRouteMatch[];
1630 patches?: RSCRouteManifest[];
1631 nonce?: string;
1632 formState?: unknown;
1633};
1634type RSCManifestPayload = {
1635 type: "manifest";
1636 patches: RSCRouteManifest[];
1637};
1638type RSCActionPayload = {
1639 type: "action";
1640 actionResult: Promise<unknown>;
1641 rerender?: Promise<RSCRenderPayload | RSCRedirectPayload>;
1642};
1643type RSCRedirectPayload = {
1644 type: "redirect";
1645 status: number;
1646 location: string;
1647 replace: boolean;
1648 reload: boolean;
1649 actionResult?: Promise<unknown>;
1650};
1651type RSCPayload = RSCRenderPayload | RSCManifestPayload | RSCActionPayload | RSCRedirectPayload;
1652type RSCMatch = {
1653 statusCode: number;
1654 headers: Headers;
1655 payload: RSCPayload;
1656};
1657type DecodeActionFunction = (formData: FormData) => Promise<() => Promise<unknown>>;
1658type DecodeFormStateFunction = (result: unknown, formData: FormData) => unknown;
1659type DecodeReplyFunction = (reply: FormData | string, { temporaryReferences }: {
1660 temporaryReferences: unknown;
1661}) => Promise<unknown[]>;
1662type LoadServerActionFunction = (id: string) => Promise<Function>;
1663/**
1664 * Matches the given routes to a Request and returns a RSC Response encoding an
1665 * `RSCPayload` for consumption by a RSC enabled client router.
1666 *
1667 * @example
1668 * import {
1669 * createTemporaryReferenceSet,
1670 * decodeAction,
1671 * decodeReply,
1672 * loadServerAction,
1673 * renderToReadableStream,
1674 * } from "@vitejs/plugin-rsc/rsc";
1675 * import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
1676 *
1677 * matchRSCServerRequest({
1678 * createTemporaryReferenceSet,
1679 * decodeAction,
1680 * decodeFormState,
1681 * decodeReply,
1682 * loadServerAction,
1683 * request,
1684 * routes: routes(),
1685 * generateResponse(match) {
1686 * return new Response(
1687 * renderToReadableStream(match.payload),
1688 * {
1689 * status: match.statusCode,
1690 * headers: match.headers,
1691 * }
1692 * );
1693 * },
1694 * });
1695 *
1696 * @name unstable_matchRSCServerRequest
1697 * @public
1698 * @category RSC
1699 * @mode data
1700 * @param opts Options
1701 * @param opts.basename The basename to use when matching the request.
1702 * @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
1703 * function, responsible for loading a server action.
1704 * @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
1705 * function, used to decode the server function's arguments and bind them to the
1706 * implementation for invocation by the router.
1707 * @param opts.decodeFormState A function responsible for decoding form state for
1708 * progressively enhanceable forms with `useActionState` using your
1709 * `react-server-dom-xyz/server`'s `decodeFormState`.
1710 * @param opts.generateResponse A function responsible for using your
1711 * `renderToReadableStream` to generate a Response encoding the `RSCPayload`.
1712 * @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
1713 * `loadServerAction` function, used to load a server action by ID.
1714 * @param opts.request The request to match against.
1715 * @param opts.requestContext An instance of `unstable_RouterContextProvider`
1716 * that should be created per request, to be passed to loaders, actions and middleware.
1717 * @param opts.routes Your route definitions.
1718 * @param opts.createTemporaryReferenceSet A function that returns a temporary
1719 * reference set for the request, used to track temporary references in the RSC stream.
1720 * @param opts.onError An optional error handler that will be called with any
1721 * errors that occur during the request processing.
1722 * @returns A Response that contains the RSC data for hydration.
1723 */
1724declare function matchRSCServerRequest({ createTemporaryReferenceSet, basename, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
1725 createTemporaryReferenceSet: () => unknown;
1726 basename?: string;
1727 decodeReply?: DecodeReplyFunction;
1728 decodeAction?: DecodeActionFunction;
1729 decodeFormState?: DecodeFormStateFunction;
1730 requestContext?: unstable_RouterContextProvider;
1731 loadServerAction?: LoadServerActionFunction;
1732 onError?: (error: unknown) => void;
1733 request: Request;
1734 routes: RSCRouteConfigEntry[];
1735 generateResponse: (match: RSCMatch, { temporaryReferences, }: {
1736 temporaryReferences: unknown;
1737 }) => Response;
1738}): Promise<Response>;
1739
1740interface CookieSignatureOptions {
1741 /**
1742 * An array of secrets that may be used to sign/unsign the value of a cookie.
1743 *
1744 * The array makes it easy to rotate secrets. New secrets should be added to
1745 * the beginning of the array. `cookie.serialize()` will always use the first
1746 * value in the array, but `cookie.parse()` may use any of them so that
1747 * cookies that were signed with older secrets still work.
1748 */
1749 secrets?: string[];
1750}
1751type CookieOptions = ParseOptions & SerializeOptions & CookieSignatureOptions;
1752/**
1753 * A HTTP cookie.
1754 *
1755 * A Cookie is a logical container for metadata about a HTTP cookie; its name
1756 * and options. But it doesn't contain a value. Instead, it has `parse()` and
1757 * `serialize()` methods that allow a single instance to be reused for
1758 * parsing/encoding multiple different values.
1759 *
1760 * @see https://remix.run/utils/cookies#cookie-api
1761 */
1762interface Cookie {
1763 /**
1764 * The name of the cookie, used in the `Cookie` and `Set-Cookie` headers.
1765 */
1766 readonly name: string;
1767 /**
1768 * True if this cookie uses one or more secrets for verification.
1769 */
1770 readonly isSigned: boolean;
1771 /**
1772 * The Date this cookie expires.
1773 *
1774 * Note: This is calculated at access time using `maxAge` when no `expires`
1775 * option is provided to `createCookie()`.
1776 */
1777 readonly expires?: Date;
1778 /**
1779 * Parses a raw `Cookie` header and returns the value of this cookie or
1780 * `null` if it's not present.
1781 */
1782 parse(cookieHeader: string | null, options?: ParseOptions): Promise<any>;
1783 /**
1784 * Serializes the given value to a string and returns the `Set-Cookie`
1785 * header.
1786 */
1787 serialize(value: any, options?: SerializeOptions): Promise<string>;
1788}
1789/**
1790 * Creates a logical container for managing a browser cookie from the server.
1791 */
1792declare const createCookie: (name: string, cookieOptions?: CookieOptions) => Cookie;
1793type IsCookieFunction = (object: any) => object is Cookie;
1794/**
1795 * Returns true if an object is a Remix cookie container.
1796 *
1797 * @see https://remix.run/utils/cookies#iscookie
1798 */
1799declare const isCookie: IsCookieFunction;
1800
1801/**
1802 * An object of name/value pairs to be used in the session.
1803 */
1804interface SessionData {
1805 [name: string]: any;
1806}
1807/**
1808 * Session persists data across HTTP requests.
1809 *
1810 * @see https://reactrouter.com/explanation/sessions-and-cookies#sessions
1811 */
1812interface Session<Data = SessionData, FlashData = Data> {
1813 /**
1814 * A unique identifier for this session.
1815 *
1816 * Note: This will be the empty string for newly created sessions and
1817 * sessions that are not backed by a database (i.e. cookie-based sessions).
1818 */
1819 readonly id: string;
1820 /**
1821 * The raw data contained in this session.
1822 *
1823 * This is useful mostly for SessionStorage internally to access the raw
1824 * session data to persist.
1825 */
1826 readonly data: FlashSessionData<Data, FlashData>;
1827 /**
1828 * Returns `true` if the session has a value for the given `name`, `false`
1829 * otherwise.
1830 */
1831 has(name: (keyof Data | keyof FlashData) & string): boolean;
1832 /**
1833 * Returns the value for the given `name` in this session.
1834 */
1835 get<Key extends (keyof Data | keyof FlashData) & string>(name: Key): (Key extends keyof Data ? Data[Key] : undefined) | (Key extends keyof FlashData ? FlashData[Key] : undefined) | undefined;
1836 /**
1837 * Sets a value in the session for the given `name`.
1838 */
1839 set<Key extends keyof Data & string>(name: Key, value: Data[Key]): void;
1840 /**
1841 * Sets a value in the session that is only valid until the next `get()`.
1842 * This can be useful for temporary values, like error messages.
1843 */
1844 flash<Key extends keyof FlashData & string>(name: Key, value: FlashData[Key]): void;
1845 /**
1846 * Removes a value from the session.
1847 */
1848 unset(name: keyof Data & string): void;
1849}
1850type FlashSessionData<Data, FlashData> = Partial<Data & {
1851 [Key in keyof FlashData as FlashDataKey<Key & string>]: FlashData[Key];
1852}>;
1853type FlashDataKey<Key extends string> = `__flash_${Key}__`;
1854type CreateSessionFunction = <Data = SessionData, FlashData = Data>(initialData?: Data, id?: string) => Session<Data, FlashData>;
1855/**
1856 * Creates a new Session object.
1857 *
1858 * Note: This function is typically not invoked directly by application code.
1859 * Instead, use a `SessionStorage` object's `getSession` method.
1860 */
1861declare const createSession: CreateSessionFunction;
1862type IsSessionFunction = (object: any) => object is Session;
1863/**
1864 * Returns true if an object is a React Router session.
1865 *
1866 * @see https://reactrouter.com/api/utils/isSession
1867 */
1868declare const isSession: IsSessionFunction;
1869/**
1870 * SessionStorage stores session data between HTTP requests and knows how to
1871 * parse and create cookies.
1872 *
1873 * A SessionStorage creates Session objects using a `Cookie` header as input.
1874 * Then, later it generates the `Set-Cookie` header to be used in the response.
1875 */
1876interface SessionStorage<Data = SessionData, FlashData = Data> {
1877 /**
1878 * Parses a Cookie header from a HTTP request and returns the associated
1879 * Session. If there is no session associated with the cookie, this will
1880 * return a new Session with no data.
1881 */
1882 getSession: (cookieHeader?: string | null, options?: ParseOptions) => Promise<Session<Data, FlashData>>;
1883 /**
1884 * Stores all data in the Session and returns the Set-Cookie header to be
1885 * used in the HTTP response.
1886 */
1887 commitSession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
1888 /**
1889 * Deletes all data associated with the Session and returns the Set-Cookie
1890 * header to be used in the HTTP response.
1891 */
1892 destroySession: (session: Session<Data, FlashData>, options?: SerializeOptions) => Promise<string>;
1893}
1894/**
1895 * SessionIdStorageStrategy is designed to allow anyone to easily build their
1896 * own SessionStorage using `createSessionStorage(strategy)`.
1897 *
1898 * This strategy describes a common scenario where the session id is stored in
1899 * a cookie but the actual session data is stored elsewhere, usually in a
1900 * database or on disk. A set of create, read, update, and delete operations
1901 * are provided for managing the session data.
1902 */
1903interface SessionIdStorageStrategy<Data = SessionData, FlashData = Data> {
1904 /**
1905 * The Cookie used to store the session id, or options used to automatically
1906 * create one.
1907 */
1908 cookie?: Cookie | (CookieOptions & {
1909 name?: string;
1910 });
1911 /**
1912 * Creates a new record with the given data and returns the session id.
1913 */
1914 createData: (data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<string>;
1915 /**
1916 * Returns data for a given session id, or `null` if there isn't any.
1917 */
1918 readData: (id: string) => Promise<FlashSessionData<Data, FlashData> | null>;
1919 /**
1920 * Updates data for the given session id.
1921 */
1922 updateData: (id: string, data: FlashSessionData<Data, FlashData>, expires?: Date) => Promise<void>;
1923 /**
1924 * Deletes data for a given session id from the data store.
1925 */
1926 deleteData: (id: string) => Promise<void>;
1927}
1928/**
1929 * Creates a SessionStorage object using a SessionIdStorageStrategy.
1930 *
1931 * Note: This is a low-level API that should only be used if none of the
1932 * existing session storage options meet your requirements.
1933 */
1934declare function createSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg, createData, readData, updateData, deleteData, }: SessionIdStorageStrategy<Data, FlashData>): SessionStorage<Data, FlashData>;
1935
1936interface CookieSessionStorageOptions {
1937 /**
1938 * The Cookie used to store the session data on the client, or options used
1939 * to automatically create one.
1940 */
1941 cookie?: SessionIdStorageStrategy["cookie"];
1942}
1943/**
1944 * Creates and returns a SessionStorage object that stores all session data
1945 * directly in the session cookie itself.
1946 *
1947 * This has the advantage that no database or other backend services are
1948 * needed, and can help to simplify some load-balanced scenarios. However, it
1949 * also has the limitation that serialized session data may not exceed the
1950 * browser's maximum cookie size. Trade-offs!
1951 */
1952declare function createCookieSessionStorage<Data = SessionData, FlashData = Data>({ cookie: cookieArg }?: CookieSessionStorageOptions): SessionStorage<Data, FlashData>;
1953
1954interface MemorySessionStorageOptions {
1955 /**
1956 * The Cookie used to store the session id on the client, or options used
1957 * to automatically create one.
1958 */
1959 cookie?: SessionIdStorageStrategy["cookie"];
1960}
1961/**
1962 * Creates and returns a simple in-memory SessionStorage object, mostly useful
1963 * for testing and as a reference implementation.
1964 *
1965 * Note: This storage does not scale beyond a single process, so it is not
1966 * suitable for most production scenarios.
1967 */
1968declare function createMemorySessionStorage<Data = SessionData, FlashData = Data>({ cookie }?: MemorySessionStorageOptions): SessionStorage<Data, FlashData>;
1969
1970export { type Cookie, type CookieOptions, type CookieSignatureOptions, type FlashSessionData, type IsCookieFunction, type IsSessionFunction, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, createCookie, createCookieSessionStorage, createMemorySessionStorage, createSession, createSessionStorage, createStaticHandler, data, isCookie, isSession, matchRoutes, redirect, redirectDocument, replace, type DecodeActionFunction as unstable_DecodeActionFunction, type DecodeFormStateFunction as unstable_DecodeFormStateFunction, type DecodeReplyFunction as unstable_DecodeReplyFunction, type LoadServerActionFunction as unstable_LoadServerActionFunction, type unstable_MiddlewareFunction, type unstable_MiddlewareNextFunction, type RSCManifestPayload as unstable_RSCManifestPayload, type RSCMatch as unstable_RSCMatch, type RSCPayload as unstable_RSCPayload, type RSCRenderPayload as unstable_RSCRenderPayload, type RSCRouteConfig as unstable_RSCRouteConfig, type RSCRouteConfigEntry as unstable_RSCRouteConfigEntry, type RSCRouteManifest as unstable_RSCRouteManifest, type RSCRouteMatch as unstable_RSCRouteMatch, type unstable_RouterContext, unstable_RouterContextProvider, unstable_createContext, matchRSCServerRequest as unstable_matchRSCServerRequest };