UNPKG

55 kBTypeScriptView Raw
1import * as React from 'react';
2import { ComponentType, ReactElement } from 'react';
3
4/**
5 * Actions represent the type of change to a location value.
6 */
7declare enum Action {
8 /**
9 * A POP indicates a change to an arbitrary index in the history stack, such
10 * as a back or forward navigation. It does not describe the direction of the
11 * navigation, only that the current index changed.
12 *
13 * Note: This is the default action for newly created history objects.
14 */
15 Pop = "POP",
16 /**
17 * A PUSH indicates a new entry being added to the history stack, such as when
18 * a link is clicked and a new page loads. When this happens, all subsequent
19 * entries in the stack are lost.
20 */
21 Push = "PUSH",
22 /**
23 * A REPLACE indicates the entry at the current index in the history stack
24 * being replaced by a new one.
25 */
26 Replace = "REPLACE"
27}
28/**
29 * The pathname, search, and hash values of a URL.
30 */
31interface Path {
32 /**
33 * A URL pathname, beginning with a /.
34 */
35 pathname: string;
36 /**
37 * A URL search string, beginning with a ?.
38 */
39 search: string;
40 /**
41 * A URL fragment identifier, beginning with a #.
42 */
43 hash: string;
44}
45/**
46 * An entry in a history stack. A location contains information about the
47 * URL path, as well as possibly some arbitrary state and a key.
48 */
49interface Location<State = any> extends Path {
50 /**
51 * A value of arbitrary data associated with this location.
52 */
53 state: State;
54 /**
55 * A unique string associated with this location. May be used to safely store
56 * and retrieve data in some other storage API, like `localStorage`.
57 *
58 * Note: This value is always "default" on the initial location.
59 */
60 key: string;
61}
62/**
63 * A change to the current location.
64 */
65interface Update {
66 /**
67 * The action that triggered the change.
68 */
69 action: Action;
70 /**
71 * The new location.
72 */
73 location: Location;
74 /**
75 * The delta between this location and the former location in the history stack
76 */
77 delta: number | null;
78}
79/**
80 * A function that receives notifications about location changes.
81 */
82interface Listener {
83 (update: Update): void;
84}
85/**
86 * Describes a location that is the destination of some navigation used in
87 * {@link Link}, {@link useNavigate}, etc.
88 */
89type To = string | Partial<Path>;
90/**
91 * A history is an interface to the navigation stack. The history serves as the
92 * source of truth for the current location, as well as provides a set of
93 * methods that may be used to change it.
94 *
95 * It is similar to the DOM's `window.history` object, but with a smaller, more
96 * focused API.
97 */
98interface History {
99 /**
100 * The last action that modified the current location. This will always be
101 * Action.Pop when a history instance is first created. This value is mutable.
102 */
103 readonly action: Action;
104 /**
105 * The current location. This value is mutable.
106 */
107 readonly location: Location;
108 /**
109 * Returns a valid href for the given `to` value that may be used as
110 * the value of an <a href> attribute.
111 *
112 * @param to - The destination URL
113 */
114 createHref(to: To): string;
115 /**
116 * Returns a URL for the given `to` value
117 *
118 * @param to - The destination URL
119 */
120 createURL(to: To): URL;
121 /**
122 * Encode a location the same way window.history would do (no-op for memory
123 * history) so we ensure our PUSH/REPLACE navigations for data routers
124 * behave the same as POP
125 *
126 * @param to Unencoded path
127 */
128 encodeLocation(to: To): Path;
129 /**
130 * Pushes a new location onto the history stack, increasing its length by one.
131 * If there were any entries in the stack after the current one, they are
132 * lost.
133 *
134 * @param to - The new URL
135 * @param state - Data to associate with the new location
136 */
137 push(to: To, state?: any): void;
138 /**
139 * Replaces the current location in the history stack with a new one. The
140 * location that was replaced will no longer be available.
141 *
142 * @param to - The new URL
143 * @param state - Data to associate with the new location
144 */
145 replace(to: To, state?: any): void;
146 /**
147 * Navigates `n` entries backward/forward in the history stack relative to the
148 * current index. For example, a "back" navigation would use go(-1).
149 *
150 * @param delta - The delta in the stack index
151 */
152 go(delta: number): void;
153 /**
154 * Sets up a listener that will be called whenever the current location
155 * changes.
156 *
157 * @param listener - A function that will be called when the location changes
158 * @returns unlisten - A function that may be used to stop listening
159 */
160 listen(listener: Listener): () => void;
161}
162/**
163 * A user-supplied object that describes a location. Used when providing
164 * entries to `createMemoryHistory` via its `initialEntries` option.
165 */
166type InitialEntry = string | Partial<Location>;
167/**
168 * A browser history stores the current location in regular URLs in a web
169 * browser environment. This is the standard for most web apps and provides the
170 * cleanest URLs the browser's address bar.
171 *
172 * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
173 */
174interface BrowserHistory extends UrlHistory {
175}
176type BrowserHistoryOptions = UrlHistoryOptions;
177/**
178 * Browser history stores the location in regular URLs. This is the standard for
179 * most web apps, but it requires some configuration on the server to ensure you
180 * serve the same app at multiple URLs.
181 *
182 * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
183 */
184declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
185/**
186 * @private
187 */
188declare function invariant(value: boolean, message?: string): asserts value;
189declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
190/**
191 * Creates a string URL path from the given pathname, search, and hash components.
192 *
193 * @category Utils
194 */
195declare function createPath({ pathname, search, hash, }: Partial<Path>): string;
196/**
197 * Parses a string URL path into its separate pathname, search, and hash components.
198 *
199 * @category Utils
200 */
201declare function parsePath(path: string): Partial<Path>;
202interface UrlHistory extends History {
203}
204type UrlHistoryOptions = {
205 window?: Window;
206 v5Compat?: boolean;
207};
208
209/**
210 * Map of routeId -> data returned from a loader/action/error
211 */
212interface RouteData {
213 [routeId: string]: any;
214}
215type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
216type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
217/**
218 * Users can specify either lowercase or uppercase form methods on `<Form>`,
219 * useSubmit(), `<fetcher.Form>`, etc.
220 */
221type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
222/**
223 * Active navigation/fetcher form methods are exposed in uppercase on the
224 * RouterState. This is to align with the normalization done via fetch().
225 */
226type FormMethod = UpperCaseFormMethod;
227type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
228type JsonObject = {
229 [Key in string]: JsonValue;
230} & {
231 [Key in string]?: JsonValue | undefined;
232};
233type JsonArray = JsonValue[] | readonly JsonValue[];
234type JsonPrimitive = string | number | boolean | null;
235type JsonValue = JsonPrimitive | JsonObject | JsonArray;
236/**
237 * @private
238 * Internal interface to pass around for action submissions, not intended for
239 * external consumption
240 */
241type Submission = {
242 formMethod: FormMethod;
243 formAction: string;
244 formEncType: FormEncType;
245 formData: FormData;
246 json: undefined;
247 text: undefined;
248} | {
249 formMethod: FormMethod;
250 formAction: string;
251 formEncType: FormEncType;
252 formData: undefined;
253 json: JsonValue;
254 text: undefined;
255} | {
256 formMethod: FormMethod;
257 formAction: string;
258 formEncType: FormEncType;
259 formData: undefined;
260 json: undefined;
261 text: string;
262};
263/**
264 * @private
265 * Arguments passed to route loader/action functions. Same for now but we keep
266 * this as a private implementation detail in case they diverge in the future.
267 */
268interface DataFunctionArgs<Context> {
269 request: Request;
270 params: Params;
271 context?: Context;
272}
273/**
274 * Arguments passed to loader functions
275 */
276interface LoaderFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
277}
278/**
279 * Arguments passed to action functions
280 */
281interface ActionFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
282}
283/**
284 * Loaders and actions can return anything except `undefined` (`null` is a
285 * valid return value if there is no data to return). Responses are preferred
286 * and will ease any future migration to Remix
287 */
288type DataFunctionValue = Response | NonNullable<unknown> | null;
289type DataFunctionReturnValue = Promise<DataFunctionValue> | DataFunctionValue;
290/**
291 * Route loader function signature
292 */
293type LoaderFunction<Context = any> = {
294 (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
295} & {
296 hydrate?: boolean;
297};
298/**
299 * Route action function signature
300 */
301interface ActionFunction<Context = any> {
302 (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
303}
304/**
305 * Arguments passed to shouldRevalidate function
306 */
307interface ShouldRevalidateFunctionArgs {
308 currentUrl: URL;
309 currentParams: AgnosticDataRouteMatch["params"];
310 nextUrl: URL;
311 nextParams: AgnosticDataRouteMatch["params"];
312 formMethod?: Submission["formMethod"];
313 formAction?: Submission["formAction"];
314 formEncType?: Submission["formEncType"];
315 text?: Submission["text"];
316 formData?: Submission["formData"];
317 json?: Submission["json"];
318 actionStatus?: number;
319 actionResult?: any;
320 defaultShouldRevalidate: boolean;
321}
322/**
323 * Route shouldRevalidate function signature. This runs after any submission
324 * (navigation or fetcher), so we flatten the navigation/fetcher submission
325 * onto the arguments. It shouldn't matter whether it came from a navigation
326 * or a fetcher, what really matters is the URLs and the formData since loaders
327 * have to re-run based on the data models that were potentially mutated.
328 */
329interface ShouldRevalidateFunction {
330 (args: ShouldRevalidateFunctionArgs): boolean;
331}
332interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
333 shouldLoad: boolean;
334 resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
335}
336interface DataStrategyFunctionArgs<Context = any> extends DataFunctionArgs<Context> {
337 matches: DataStrategyMatch[];
338 fetcherKey: string | null;
339}
340/**
341 * Result from a loader or action called via dataStrategy
342 */
343interface DataStrategyResult {
344 type: "data" | "error";
345 result: unknown;
346}
347interface DataStrategyFunction {
348 (args: DataStrategyFunctionArgs): Promise<Record<string, DataStrategyResult>>;
349}
350type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
351 path: string;
352 matches: M[];
353 patch: (routeId: string | null, children: O[]) => void;
354};
355type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => void | Promise<void>;
356/**
357 * Function provided by the framework-aware layers to set any framework-specific
358 * properties from framework-agnostic properties
359 */
360interface MapRoutePropertiesFunction {
361 (route: AgnosticRouteObject): {
362 hasErrorBoundary: boolean;
363 } & Record<string, any>;
364}
365/**
366 * Keys we cannot change from within a lazy() function. We spread all other keys
367 * onto the route. Either they're meaningful to the router, or they'll get
368 * ignored.
369 */
370type ImmutableRouteKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
371type RequireOne<T, Key = keyof T> = Exclude<{
372 [K in keyof T]: K extends Key ? Omit<T, K> & Required<Pick<T, K>> : never;
373}[keyof T], undefined>;
374/**
375 * lazy() function to load a route definition, which can add non-matching
376 * related properties to a route
377 */
378interface LazyRouteFunction<R extends AgnosticRouteObject> {
379 (): Promise<RequireOne<Omit<R, ImmutableRouteKey>>>;
380}
381/**
382 * Base RouteObject with common props shared by all types of routes
383 */
384type AgnosticBaseRouteObject = {
385 caseSensitive?: boolean;
386 path?: string;
387 id?: string;
388 loader?: LoaderFunction | boolean;
389 action?: ActionFunction | boolean;
390 hasErrorBoundary?: boolean;
391 shouldRevalidate?: ShouldRevalidateFunction;
392 handle?: any;
393 lazy?: LazyRouteFunction<AgnosticBaseRouteObject>;
394};
395/**
396 * Index routes must not have children
397 */
398type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
399 children?: undefined;
400 index: true;
401};
402/**
403 * Non-index routes may have children, but cannot have index
404 */
405type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
406 children?: AgnosticRouteObject[];
407 index?: false;
408};
409/**
410 * A route object represents a logical route, with (optionally) its child
411 * routes organized in a tree-like structure.
412 */
413type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
414type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
415 id: string;
416};
417type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
418 children?: AgnosticDataRouteObject[];
419 id: string;
420};
421/**
422 * A data route object, which is just a RouteObject with a required unique ID
423 */
424type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
425type RouteManifest<R = AgnosticDataRouteObject> = Record<string, R | undefined>;
426type Regex_az = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
427type Regez_AZ = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
428type Regex_09 = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
429type Regex_w = Regex_az | Regez_AZ | Regex_09 | "_";
430type ParamChar = Regex_w | "-";
431type RegexMatchPlus<CharPattern extends string, T extends string> = T extends `${infer First}${infer Rest}` ? First extends CharPattern ? RegexMatchPlus<CharPattern, Rest> extends never ? First : `${First}${RegexMatchPlus<CharPattern, Rest>}` : never : never;
432type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?${string}` ? RegexMatchPlus<ParamChar, Optional> : RegexMatchPlus<ParamChar, Param> : never;
433type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
434type ParamParseKey<Segment extends string> = [
435 PathParam<Segment>
436] extends [never] ? string : PathParam<Segment>;
437/**
438 * The parameters that were parsed from the URL path.
439 */
440type Params<Key extends string = string> = {
441 readonly [key in Key]: string | undefined;
442};
443/**
444 * A RouteMatch contains info about how a route matched a URL.
445 */
446interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
447 /**
448 * The names and values of dynamic parameters in the URL.
449 */
450 params: Params<ParamKey>;
451 /**
452 * The portion of the URL pathname that was matched.
453 */
454 pathname: string;
455 /**
456 * The portion of the URL pathname that was matched before child routes.
457 */
458 pathnameBase: string;
459 /**
460 * The route object that was used to match.
461 */
462 route: RouteObjectType;
463}
464interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
465}
466/**
467 * Matches the given routes to a location and returns the match data.
468 *
469 * @category Utils
470 */
471declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
472interface UIMatch<Data = unknown, Handle = unknown> {
473 id: string;
474 pathname: string;
475 params: AgnosticRouteMatch["params"];
476 data: Data;
477 handle: Handle;
478}
479/**
480 * Returns a path with params interpolated.
481 *
482 * @category Utils
483 */
484declare function generatePath<Path extends string>(originalPath: Path, params?: {
485 [key in PathParam<Path>]: string | null;
486}): string;
487/**
488 * A PathPattern is used to match on some portion of a URL pathname.
489 */
490interface PathPattern<Path extends string = string> {
491 /**
492 * A string to match against a URL pathname. May contain `:id`-style segments
493 * to indicate placeholders for dynamic parameters. May also end with `/*` to
494 * indicate matching the rest of the URL pathname.
495 */
496 path: Path;
497 /**
498 * Should be `true` if the static portions of the `path` should be matched in
499 * the same case.
500 */
501 caseSensitive?: boolean;
502 /**
503 * Should be `true` if this pattern should match the entire URL pathname.
504 */
505 end?: boolean;
506}
507/**
508 * A PathMatch contains info about how a PathPattern matched on a URL pathname.
509 */
510interface PathMatch<ParamKey extends string = string> {
511 /**
512 * The names and values of dynamic parameters in the URL.
513 */
514 params: Params<ParamKey>;
515 /**
516 * The portion of the URL pathname that was matched.
517 */
518 pathname: string;
519 /**
520 * The portion of the URL pathname that was matched before child routes.
521 */
522 pathnameBase: string;
523 /**
524 * The pattern that was used to match.
525 */
526 pattern: PathPattern;
527}
528/**
529 * Performs pattern matching on a URL pathname and returns information about
530 * the match.
531 *
532 * @category Utils
533 */
534declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
535/**
536 * Returns a resolved path object relative to the given pathname.
537 *
538 * @category Utils
539 */
540declare function resolvePath(to: To, fromPathname?: string): Path;
541declare class DataWithResponseInit<D> {
542 type: string;
543 data: D;
544 init: ResponseInit | null;
545 constructor(data: D, init?: ResponseInit);
546}
547/**
548 * Create "responses" that contain `status`/`headers` without forcing
549 * serialization into an actual `Response` - used by Remix single fetch
550 *
551 * @category Utils
552 */
553declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
554type RedirectFunction = (url: string, init?: number | ResponseInit) => Redirect;
555declare const redirectSymbol: unique symbol;
556type Redirect = Response & {
557 [redirectSymbol]: never;
558};
559/**
560 * A redirect response. Sets the status code and the `Location` header.
561 * Defaults to "302 Found".
562 *
563 * @category Utils
564 */
565declare const redirect: RedirectFunction;
566/**
567 * A redirect response that will force a document reload to the new location.
568 * Sets the status code and the `Location` header.
569 * Defaults to "302 Found".
570 *
571 * @category Utils
572 */
573declare const redirectDocument: RedirectFunction;
574/**
575 * A redirect response that will perform a `history.replaceState` instead of a
576 * `history.pushState` for client-side navigation redirects.
577 * Sets the status code and the `Location` header.
578 * Defaults to "302 Found".
579 *
580 * @category Utils
581 */
582declare const replace: RedirectFunction;
583type ErrorResponse = {
584 status: number;
585 statusText: string;
586 data: any;
587};
588/**
589 * @private
590 * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
591 *
592 * We don't export the class for public use since it's an implementation
593 * detail, but we export the interface above so folks can build their own
594 * abstractions around instances via isRouteErrorResponse()
595 */
596declare class ErrorResponseImpl implements ErrorResponse {
597 status: number;
598 statusText: string;
599 data: any;
600 private error?;
601 private internal;
602 constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
603}
604/**
605 * Check if the given error is an ErrorResponse generated from a 4xx/5xx
606 * Response thrown from an action/loader
607 *
608 * @category Utils
609 */
610declare function isRouteErrorResponse(error: any): error is ErrorResponse;
611
612/**
613 * A Router instance manages all navigation and data loading/mutations
614 */
615interface Router {
616 /**
617 * @private
618 * PRIVATE - DO NOT USE
619 *
620 * Return the basename for the router
621 */
622 get basename(): RouterInit["basename"];
623 /**
624 * @private
625 * PRIVATE - DO NOT USE
626 *
627 * Return the future config for the router
628 */
629 get future(): FutureConfig;
630 /**
631 * @private
632 * PRIVATE - DO NOT USE
633 *
634 * Return the current state of the router
635 */
636 get state(): RouterState;
637 /**
638 * @private
639 * PRIVATE - DO NOT USE
640 *
641 * Return the routes for this router instance
642 */
643 get routes(): AgnosticDataRouteObject[];
644 /**
645 * @private
646 * PRIVATE - DO NOT USE
647 *
648 * Return the window associated with the router
649 */
650 get window(): RouterInit["window"];
651 /**
652 * @private
653 * PRIVATE - DO NOT USE
654 *
655 * Initialize the router, including adding history listeners and kicking off
656 * initial data fetches. Returns a function to cleanup listeners and abort
657 * any in-progress loads
658 */
659 initialize(): Router;
660 /**
661 * @private
662 * PRIVATE - DO NOT USE
663 *
664 * Subscribe to router.state updates
665 *
666 * @param fn function to call with the new state
667 */
668 subscribe(fn: RouterSubscriber): () => void;
669 /**
670 * @private
671 * PRIVATE - DO NOT USE
672 *
673 * Enable scroll restoration behavior in the router
674 *
675 * @param savedScrollPositions Object that will manage positions, in case
676 * it's being restored from sessionStorage
677 * @param getScrollPosition Function to get the active Y scroll position
678 * @param getKey Function to get the key to use for restoration
679 */
680 enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
681 /**
682 * @private
683 * PRIVATE - DO NOT USE
684 *
685 * Navigate forward/backward in the history stack
686 * @param to Delta to move in the history stack
687 */
688 navigate(to: number): Promise<void>;
689 /**
690 * Navigate to the given path
691 * @param to Path to navigate to
692 * @param opts Navigation options (method, submission, etc.)
693 */
694 navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
695 /**
696 * @private
697 * PRIVATE - DO NOT USE
698 *
699 * Trigger a fetcher load/submission
700 *
701 * @param key Fetcher key
702 * @param routeId Route that owns the fetcher
703 * @param href href to fetch
704 * @param opts Fetcher options, (method, submission, etc.)
705 */
706 fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
707 /**
708 * @private
709 * PRIVATE - DO NOT USE
710 *
711 * Trigger a revalidation of all current route loaders and fetcher loads
712 */
713 revalidate(): Promise<void>;
714 /**
715 * @private
716 * PRIVATE - DO NOT USE
717 *
718 * Utility function to create an href for the given location
719 * @param location
720 */
721 createHref(location: Location | URL): string;
722 /**
723 * @private
724 * PRIVATE - DO NOT USE
725 *
726 * Utility function to URL encode a destination path according to the internal
727 * history implementation
728 * @param to
729 */
730 encodeLocation(to: To): Path;
731 /**
732 * @private
733 * PRIVATE - DO NOT USE
734 *
735 * Get/create a fetcher for the given key
736 * @param key
737 */
738 getFetcher<TData = any>(key: string): Fetcher<TData>;
739 /**
740 * @private
741 * PRIVATE - DO NOT USE
742 *
743 * Delete the fetcher for a given key
744 * @param key
745 */
746 deleteFetcher(key: string): void;
747 /**
748 * @private
749 * PRIVATE - DO NOT USE
750 *
751 * Cleanup listeners and abort any in-progress loads
752 */
753 dispose(): void;
754 /**
755 * @private
756 * PRIVATE - DO NOT USE
757 *
758 * Get a navigation blocker
759 * @param key The identifier for the blocker
760 * @param fn The blocker function implementation
761 */
762 getBlocker(key: string, fn: BlockerFunction): Blocker;
763 /**
764 * @private
765 * PRIVATE - DO NOT USE
766 *
767 * Delete a navigation blocker
768 * @param key The identifier for the blocker
769 */
770 deleteBlocker(key: string): void;
771 /**
772 * @private
773 * PRIVATE DO NOT USE
774 *
775 * Patch additional children routes into an existing parent route
776 * @param routeId The parent route id or a callback function accepting `patch`
777 * to perform batch patching
778 * @param children The additional children routes
779 */
780 patchRoutes(routeId: string | null, children: AgnosticRouteObject[]): void;
781 /**
782 * @private
783 * PRIVATE - DO NOT USE
784 *
785 * HMR needs to pass in-flight route updates to React Router
786 * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
787 */
788 _internalSetRoutes(routes: AgnosticRouteObject[]): void;
789 /**
790 * @private
791 * PRIVATE - DO NOT USE
792 *
793 * Internal fetch AbortControllers accessed by unit tests
794 */
795 _internalFetchControllers: Map<string, AbortController>;
796}
797/**
798 * State maintained internally by the router. During a navigation, all states
799 * reflect the the "old" location unless otherwise noted.
800 */
801interface RouterState {
802 /**
803 * The action of the most recent navigation
804 */
805 historyAction: Action;
806 /**
807 * The current location reflected by the router
808 */
809 location: Location;
810 /**
811 * The current set of route matches
812 */
813 matches: AgnosticDataRouteMatch[];
814 /**
815 * Tracks whether we've completed our initial data load
816 */
817 initialized: boolean;
818 /**
819 * Current scroll position we should start at for a new view
820 * - number -> scroll position to restore to
821 * - false -> do not restore scroll at all (used during submissions)
822 * - null -> don't have a saved position, scroll to hash or top of page
823 */
824 restoreScrollPosition: number | false | null;
825 /**
826 * Indicate whether this navigation should skip resetting the scroll position
827 * if we are unable to restore the scroll position
828 */
829 preventScrollReset: boolean;
830 /**
831 * Tracks the state of the current navigation
832 */
833 navigation: Navigation;
834 /**
835 * Tracks any in-progress revalidations
836 */
837 revalidation: RevalidationState;
838 /**
839 * Data from the loaders for the current matches
840 */
841 loaderData: RouteData;
842 /**
843 * Data from the action for the current matches
844 */
845 actionData: RouteData | null;
846 /**
847 * Errors caught from loaders for the current matches
848 */
849 errors: RouteData | null;
850 /**
851 * Map of current fetchers
852 */
853 fetchers: Map<string, Fetcher>;
854 /**
855 * Map of current blockers
856 */
857 blockers: Map<string, Blocker>;
858}
859/**
860 * Data that can be passed into hydrate a Router from SSR
861 */
862type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
863/**
864 * Future flags to toggle new feature behavior
865 */
866interface FutureConfig {
867}
868/**
869 * Initialization options for createRouter
870 */
871interface RouterInit {
872 routes: AgnosticRouteObject[];
873 history: History;
874 basename?: string;
875 mapRouteProperties?: MapRoutePropertiesFunction;
876 future?: Partial<FutureConfig>;
877 hydrationData?: HydrationState;
878 window?: Window;
879 dataStrategy?: DataStrategyFunction;
880 patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
881}
882/**
883 * State returned from a server-side query() call
884 */
885interface StaticHandlerContext {
886 basename: Router["basename"];
887 location: RouterState["location"];
888 matches: RouterState["matches"];
889 loaderData: RouterState["loaderData"];
890 actionData: RouterState["actionData"];
891 errors: RouterState["errors"];
892 statusCode: number;
893 loaderHeaders: Record<string, Headers>;
894 actionHeaders: Record<string, Headers>;
895 _deepestRenderedBoundaryId?: string | null;
896}
897/**
898 * A StaticHandler instance manages a singular SSR navigation/fetch event
899 */
900interface StaticHandler {
901 dataRoutes: AgnosticDataRouteObject[];
902 query(request: Request, opts?: {
903 requestContext?: unknown;
904 skipLoaderErrorBubbling?: boolean;
905 dataStrategy?: DataStrategyFunction;
906 }): Promise<StaticHandlerContext | Response>;
907 queryRoute(request: Request, opts?: {
908 routeId?: string;
909 requestContext?: unknown;
910 dataStrategy?: DataStrategyFunction;
911 }): Promise<any>;
912}
913type ViewTransitionOpts = {
914 currentLocation: Location;
915 nextLocation: Location;
916};
917/**
918 * Subscriber function signature for changes to router state
919 */
920interface RouterSubscriber {
921 (state: RouterState, opts: {
922 deletedFetchers: string[];
923 viewTransitionOpts?: ViewTransitionOpts;
924 flushSync: boolean;
925 }): void;
926}
927/**
928 * Function signature for determining the key to be used in scroll restoration
929 * for a given location
930 */
931interface GetScrollRestorationKeyFunction {
932 (location: Location, matches: UIMatch[]): string | null;
933}
934/**
935 * Function signature for determining the current scroll position
936 */
937interface GetScrollPositionFunction {
938 (): number;
939}
940/**
941 - "route": relative to the route hierarchy so `..` means remove all segments of the current route even if it has many. For example, a `route("posts/:id")` would have both `:id` and `posts` removed from the url.
942 - "path": relative to the pathname so `..` means remove one segment of the pathname. For example, a `route("posts/:id")` would have only `:id` removed from the url.
943 */
944type RelativeRoutingType = "route" | "path";
945type BaseNavigateOrFetchOptions = {
946 preventScrollReset?: boolean;
947 relative?: RelativeRoutingType;
948 flushSync?: boolean;
949};
950type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
951 replace?: boolean;
952 state?: any;
953 fromRouteId?: string;
954 viewTransition?: boolean;
955};
956type BaseSubmissionOptions = {
957 formMethod?: HTMLFormMethod;
958 formEncType?: FormEncType;
959} & ({
960 formData: FormData;
961 body?: undefined;
962} | {
963 formData?: undefined;
964 body: any;
965});
966/**
967 * Options for a navigate() call for a normal (non-submission) navigation
968 */
969type LinkNavigateOptions = BaseNavigateOptions;
970/**
971 * Options for a navigate() call for a submission navigation
972 */
973type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
974/**
975 * Options to pass to navigate() for a navigation
976 */
977type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
978/**
979 * Options for a fetch() load
980 */
981type LoadFetchOptions = BaseNavigateOrFetchOptions;
982/**
983 * Options for a fetch() submission
984 */
985type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
986/**
987 * Options to pass to fetch()
988 */
989type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
990/**
991 * Potential states for state.navigation
992 */
993type NavigationStates = {
994 Idle: {
995 state: "idle";
996 location: undefined;
997 formMethod: undefined;
998 formAction: undefined;
999 formEncType: undefined;
1000 formData: undefined;
1001 json: undefined;
1002 text: undefined;
1003 };
1004 Loading: {
1005 state: "loading";
1006 location: Location;
1007 formMethod: Submission["formMethod"] | undefined;
1008 formAction: Submission["formAction"] | undefined;
1009 formEncType: Submission["formEncType"] | undefined;
1010 formData: Submission["formData"] | undefined;
1011 json: Submission["json"] | undefined;
1012 text: Submission["text"] | undefined;
1013 };
1014 Submitting: {
1015 state: "submitting";
1016 location: Location;
1017 formMethod: Submission["formMethod"];
1018 formAction: Submission["formAction"];
1019 formEncType: Submission["formEncType"];
1020 formData: Submission["formData"];
1021 json: Submission["json"];
1022 text: Submission["text"];
1023 };
1024};
1025type Navigation = NavigationStates[keyof NavigationStates];
1026type RevalidationState = "idle" | "loading";
1027/**
1028 * Potential states for fetchers
1029 */
1030type FetcherStates<TData = any> = {
1031 /**
1032 * The fetcher is not calling a loader or action
1033 *
1034 * ```tsx
1035 * fetcher.state === "idle"
1036 * ```
1037 */
1038 Idle: {
1039 state: "idle";
1040 formMethod: undefined;
1041 formAction: undefined;
1042 formEncType: undefined;
1043 text: undefined;
1044 formData: undefined;
1045 json: undefined;
1046 /**
1047 * If the fetcher has never been called, this will be undefined.
1048 */
1049 data: TData | undefined;
1050 };
1051 /**
1052 * The fetcher is loading data from a {@link LoaderFunction | loader} from a
1053 * call to {@link FetcherWithComponents.load | `fetcher.load`}.
1054 *
1055 * ```tsx
1056 * // somewhere
1057 * <button onClick={() => fetcher.load("/some/route") }>Load</button>
1058 *
1059 * // the state will update
1060 * fetcher.state === "loading"
1061 * ```
1062 */
1063 Loading: {
1064 state: "loading";
1065 formMethod: Submission["formMethod"] | undefined;
1066 formAction: Submission["formAction"] | undefined;
1067 formEncType: Submission["formEncType"] | undefined;
1068 text: Submission["text"] | undefined;
1069 formData: Submission["formData"] | undefined;
1070 json: Submission["json"] | undefined;
1071 data: TData | undefined;
1072 };
1073 /**
1074 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`}.
1075
1076 ```tsx
1077 // somewhere
1078 <input
1079 onChange={e => {
1080 fetcher.submit(event.currentTarget.form, { method: "post" });
1081 }}
1082 />
1083
1084 // the state will update
1085 fetcher.state === "submitting"
1086
1087 // and formData will be available
1088 fetcher.formData
1089 ```
1090 */
1091 Submitting: {
1092 state: "submitting";
1093 formMethod: Submission["formMethod"];
1094 formAction: Submission["formAction"];
1095 formEncType: Submission["formEncType"];
1096 text: Submission["text"];
1097 formData: Submission["formData"];
1098 json: Submission["json"];
1099 data: TData | undefined;
1100 };
1101};
1102type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
1103interface BlockerBlocked {
1104 state: "blocked";
1105 reset(): void;
1106 proceed(): void;
1107 location: Location;
1108}
1109interface BlockerUnblocked {
1110 state: "unblocked";
1111 reset: undefined;
1112 proceed: undefined;
1113 location: undefined;
1114}
1115interface BlockerProceeding {
1116 state: "proceeding";
1117 reset: undefined;
1118 proceed: undefined;
1119 location: Location;
1120}
1121type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1122type BlockerFunction = (args: {
1123 currentLocation: Location;
1124 nextLocation: Location;
1125 historyAction: Action;
1126}) => boolean;
1127declare const IDLE_NAVIGATION: NavigationStates["Idle"];
1128declare const IDLE_FETCHER: FetcherStates["Idle"];
1129declare const IDLE_BLOCKER: BlockerUnblocked;
1130/**
1131 * Create a router and listen to history POP navigations
1132 */
1133declare function createRouter(init: RouterInit): Router;
1134interface CreateStaticHandlerOptions {
1135 basename?: string;
1136 mapRouteProperties?: MapRoutePropertiesFunction;
1137 future?: {};
1138}
1139
1140interface IndexRouteObject {
1141 caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
1142 path?: AgnosticIndexRouteObject["path"];
1143 id?: AgnosticIndexRouteObject["id"];
1144 loader?: AgnosticIndexRouteObject["loader"];
1145 action?: AgnosticIndexRouteObject["action"];
1146 hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
1147 shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
1148 handle?: AgnosticIndexRouteObject["handle"];
1149 index: true;
1150 children?: undefined;
1151 element?: React.ReactNode | null;
1152 hydrateFallbackElement?: React.ReactNode | null;
1153 errorElement?: React.ReactNode | null;
1154 Component?: React.ComponentType | null;
1155 HydrateFallback?: React.ComponentType | null;
1156 ErrorBoundary?: React.ComponentType | null;
1157 lazy?: LazyRouteFunction<RouteObject>;
1158}
1159interface NonIndexRouteObject {
1160 caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
1161 path?: AgnosticNonIndexRouteObject["path"];
1162 id?: AgnosticNonIndexRouteObject["id"];
1163 loader?: AgnosticNonIndexRouteObject["loader"];
1164 action?: AgnosticNonIndexRouteObject["action"];
1165 hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
1166 shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
1167 handle?: AgnosticNonIndexRouteObject["handle"];
1168 index?: false;
1169 children?: RouteObject[];
1170 element?: React.ReactNode | null;
1171 hydrateFallbackElement?: React.ReactNode | null;
1172 errorElement?: React.ReactNode | null;
1173 Component?: React.ComponentType | null;
1174 HydrateFallback?: React.ComponentType | null;
1175 ErrorBoundary?: React.ComponentType | null;
1176 lazy?: LazyRouteFunction<RouteObject>;
1177}
1178type RouteObject = IndexRouteObject | NonIndexRouteObject;
1179type DataRouteObject = RouteObject & {
1180 children?: DataRouteObject[];
1181 id: string;
1182};
1183interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
1184}
1185interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
1186}
1187type PatchRoutesOnNavigationFunctionArgs = AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;
1188type PatchRoutesOnNavigationFunction = AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;
1189interface DataRouterContextObject extends Omit<NavigationContextObject, "future"> {
1190 router: Router;
1191 staticContext?: StaticHandlerContext;
1192}
1193declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
1194declare const DataRouterStateContext: React.Context<RouterState | null>;
1195type ViewTransitionContextObject = {
1196 isTransitioning: false;
1197} | {
1198 isTransitioning: true;
1199 flushSync: boolean;
1200 currentLocation: Location;
1201 nextLocation: Location;
1202};
1203declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
1204type FetchersContextObject = Map<string, any>;
1205declare const FetchersContext: React.Context<FetchersContextObject>;
1206interface NavigateOptions {
1207 replace?: boolean;
1208 state?: any;
1209 preventScrollReset?: boolean;
1210 relative?: RelativeRoutingType;
1211 flushSync?: boolean;
1212 viewTransition?: boolean;
1213}
1214/**
1215 * A Navigator is a "location changer"; it's how you get to different locations.
1216 *
1217 * Every history instance conforms to the Navigator interface, but the
1218 * distinction is useful primarily when it comes to the low-level `<Router>` API
1219 * where both the location and a navigator must be provided separately in order
1220 * to avoid "tearing" that may occur in a suspense-enabled app if the action
1221 * and/or location were to be read directly from the history instance.
1222 */
1223interface Navigator {
1224 createHref: History["createHref"];
1225 encodeLocation?: History["encodeLocation"];
1226 go: History["go"];
1227 push(to: To, state?: any, opts?: NavigateOptions): void;
1228 replace(to: To, state?: any, opts?: NavigateOptions): void;
1229}
1230interface NavigationContextObject {
1231 basename: string;
1232 navigator: Navigator;
1233 static: boolean;
1234 future: {};
1235}
1236declare const NavigationContext: React.Context<NavigationContextObject>;
1237interface LocationContextObject {
1238 location: Location;
1239 navigationType: Action;
1240}
1241declare const LocationContext: React.Context<LocationContextObject>;
1242interface RouteContextObject {
1243 outlet: React.ReactElement | null;
1244 matches: RouteMatch[];
1245 isDataRoute: boolean;
1246}
1247declare const RouteContext: React.Context<RouteContextObject>;
1248
1249type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1250type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1251interface HtmlLinkProps {
1252 /**
1253 * Address of the hyperlink
1254 */
1255 href?: string;
1256 /**
1257 * How the element handles crossorigin requests
1258 */
1259 crossOrigin?: "anonymous" | "use-credentials";
1260 /**
1261 * Relationship between the document containing the hyperlink and the destination resource
1262 */
1263 rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
1264 /**
1265 * Applicable media: "screen", "print", "(max-width: 764px)"
1266 */
1267 media?: string;
1268 /**
1269 * Integrity metadata used in Subresource Integrity checks
1270 */
1271 integrity?: string;
1272 /**
1273 * Language of the linked resource
1274 */
1275 hrefLang?: string;
1276 /**
1277 * Hint for the type of the referenced resource
1278 */
1279 type?: string;
1280 /**
1281 * Referrer policy for fetches initiated by the element
1282 */
1283 referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
1284 /**
1285 * Sizes of the icons (for rel="icon")
1286 */
1287 sizes?: string;
1288 /**
1289 * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1290 */
1291 as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
1292 /**
1293 * Color to use when customizing a site's icon (for rel="mask-icon")
1294 */
1295 color?: string;
1296 /**
1297 * Whether the link is disabled
1298 */
1299 disabled?: boolean;
1300 /**
1301 * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
1302 */
1303 title?: string;
1304 /**
1305 * Images to use in different situations, e.g., high-resolution displays,
1306 * small monitors, etc. (for rel="preload")
1307 */
1308 imageSrcSet?: string;
1309 /**
1310 * Image sizes for different page layouts (for rel="preload")
1311 */
1312 imageSizes?: string;
1313}
1314interface HtmlLinkPreloadImage extends HtmlLinkProps {
1315 /**
1316 * Relationship between the document containing the hyperlink and the destination resource
1317 */
1318 rel: "preload";
1319 /**
1320 * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1321 */
1322 as: "image";
1323 /**
1324 * Address of the hyperlink
1325 */
1326 href?: string;
1327 /**
1328 * Images to use in different situations, e.g., high-resolution displays,
1329 * small monitors, etc. (for rel="preload")
1330 */
1331 imageSrcSet: string;
1332 /**
1333 * Image sizes for different page layouts (for rel="preload")
1334 */
1335 imageSizes?: string;
1336}
1337/**
1338 * Represents a `<link>` element.
1339 *
1340 * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
1341 */
1342type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
1343 imageSizes?: never;
1344});
1345interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1346 /**
1347 * The absolute path of the page to prefetch.
1348 */
1349 page: string;
1350}
1351type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1352
1353interface RouteModules {
1354 [routeId: string]: RouteModule | undefined;
1355}
1356interface RouteModule {
1357 clientAction?: ClientActionFunction;
1358 clientLoader?: ClientLoaderFunction;
1359 ErrorBoundary?: ErrorBoundaryComponent;
1360 HydrateFallback?: HydrateFallbackComponent;
1361 Layout?: LayoutComponent;
1362 default: RouteComponent;
1363 handle?: RouteHandle;
1364 links?: LinksFunction;
1365 meta?: MetaFunction;
1366 shouldRevalidate?: ShouldRevalidateFunction;
1367}
1368/**
1369 * A function that handles data mutations for a route on the client
1370 */
1371type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
1372/**
1373 * Arguments passed to a route `clientAction` function
1374 */
1375type ClientActionFunctionArgs = ActionFunctionArgs<undefined> & {
1376 serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1377};
1378/**
1379 * A function that loads data for a route on the client
1380 */
1381type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
1382 hydrate?: boolean;
1383};
1384/**
1385 * Arguments passed to a route `clientLoader` function
1386 */
1387type ClientLoaderFunctionArgs = LoaderFunctionArgs<undefined> & {
1388 serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1389};
1390/**
1391 * ErrorBoundary to display for this route
1392 */
1393type ErrorBoundaryComponent = ComponentType;
1394/**
1395 * `<Route HydrateFallback>` component to render on initial loads
1396 * when client loaders are present
1397 */
1398type HydrateFallbackComponent = ComponentType;
1399/**
1400 * Optional, root-only `<Route Layout>` component to wrap the root content in.
1401 * Useful for defining the <html>/<head>/<body> document shell shared by the
1402 * Component, HydrateFallback, and ErrorBoundary
1403 */
1404type LayoutComponent = ComponentType<{
1405 children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
1406}>;
1407/**
1408 * A function that defines `<link>` tags to be inserted into the `<head>` of
1409 * the document on route transitions.
1410 *
1411 * @see https://remix.run/route/meta
1412 */
1413interface LinksFunction {
1414 (): LinkDescriptor[];
1415}
1416interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1417 id: RouteId;
1418 pathname: DataRouteMatch["pathname"];
1419 data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1420 handle?: RouteHandle;
1421 params: DataRouteMatch["params"];
1422 meta: MetaDescriptor[];
1423 error?: unknown;
1424}
1425type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
1426 [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1427}[keyof MatchLoaders]>;
1428interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1429 data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1430 params: Params;
1431 location: Location;
1432 matches: MetaMatches<MatchLoaders>;
1433 error?: unknown;
1434}
1435/**
1436 * A function that returns an array of data objects to use for rendering
1437 * metadata HTML tags in a route. These tags are not rendered on descendant
1438 * routes in the route hierarchy. In other words, they will only be rendered on
1439 * the route in which they are exported.
1440 *
1441 * @param Loader - The type of the current route's loader function
1442 * @param MatchLoaders - Mapping from a parent route's filepath to its loader
1443 * function type
1444 *
1445 * Note that parent route filepaths are relative to the `app/` directory.
1446 *
1447 * For example, if this meta function is for `/sales/customers/$customerId`:
1448 *
1449 * ```ts
1450 * // app/root.tsx
1451 * const loader = () => ({ hello: "world" })
1452 * export type Loader = typeof loader
1453 *
1454 * // app/routes/sales.tsx
1455 * const loader = () => ({ salesCount: 1074 })
1456 * export type Loader = typeof loader
1457 *
1458 * // app/routes/sales/customers.tsx
1459 * const loader = () => ({ customerCount: 74 })
1460 * export type Loader = typeof loader
1461 *
1462 * // app/routes/sales/customers/$customersId.tsx
1463 * import type { Loader as RootLoader } from "../../../root"
1464 * import type { Loader as SalesLoader } from "../../sales"
1465 * import type { Loader as CustomersLoader } from "../../sales/customers"
1466 *
1467 * const loader = () => ({ name: "Customer name" })
1468 *
1469 * const meta: MetaFunction<typeof loader, {
1470 * "root": RootLoader,
1471 * "routes/sales": SalesLoader,
1472 * "routes/sales/customers": CustomersLoader,
1473 * }> = ({ data, matches }) => {
1474 * const { name } = data
1475 * // ^? string
1476 * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
1477 * // ^? number
1478 * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
1479 * // ^? number
1480 * const { hello } = matches.find((match) => match.id === "root").data
1481 * // ^? "world"
1482 * }
1483 * ```
1484 */
1485interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1486 (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
1487}
1488type MetaDescriptor = {
1489 charSet: "utf-8";
1490} | {
1491 title: string;
1492} | {
1493 name: string;
1494 content: string;
1495} | {
1496 property: string;
1497 content: string;
1498} | {
1499 httpEquiv: string;
1500 content: string;
1501} | {
1502 "script:ld+json": LdJsonObject;
1503} | {
1504 tagName: "meta" | "link";
1505 [name: string]: string;
1506} | {
1507 [name: string]: unknown;
1508};
1509type LdJsonObject = {
1510 [Key in string]: LdJsonValue;
1511} & {
1512 [Key in string]?: LdJsonValue | undefined;
1513};
1514type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
1515type LdJsonPrimitive = string | number | boolean | null;
1516type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
1517/**
1518 * A React component that is rendered for a route.
1519 */
1520type RouteComponent = ComponentType<{}>;
1521/**
1522 * An arbitrary object that is associated with a route.
1523 *
1524 * @see https://remix.run/route/handle
1525 */
1526type RouteHandle = unknown;
1527
1528type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1529 [key: PropertyKey]: Serializable;
1530} | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
1531
1532type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
1533type IsAny<T> = 0 extends 1 & T ? true : false;
1534type Func = (...args: any[]) => unknown;
1535type Pretty<T> = {
1536 [K in keyof T]: T[K];
1537} & {};
1538
1539type Serialize<T> = 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> ? {
1540 [K in keyof T]: Serialize<T[K]>;
1541} : undefined;
1542type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1543type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1544type ClientData<T> = T extends Redirect ? never : T extends DataWithResponseInit<infer U> ? U : T;
1545type ServerData<T> = T extends Redirect ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1546type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1547type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1548type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1549
1550export { type HTMLFormMethod as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyFunction as D, type RouterInit as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type RouterSubscriber as J, type RouterNavigateOptions as K, type LoaderFunction as L, type MetaFunction as M, type NavigateOptions as N, type RouterFetchOptions as O, type ParamParseKey as P, type DataStrategyFunctionArgs as Q, type RouteModules as R, type SerializeFrom as S, type To as T, type UIMatch as U, type DataStrategyMatch as V, type DataStrategyResult as W, DataWithResponseInit as X, type ErrorResponse as Y, type FormEncType as Z, type FormMethod as _, type Router as a, type LazyRouteFunction as a0, type PathParam as a1, type RedirectFunction as a2, type ShouldRevalidateFunction as a3, type ShouldRevalidateFunctionArgs as a4, createPath as a5, parsePath as a6, IDLE_NAVIGATION as a7, IDLE_FETCHER as a8, IDLE_BLOCKER as a9, DataRouterContext as aA, DataRouterStateContext as aB, FetchersContext as aC, LocationContext as aD, NavigationContext as aE, RouteContext as aF, ViewTransitionContext as aG, type RouteModule as aH, type History as aI, type ServerDataFrom as aJ, type ClientDataFrom as aK, type Func as aL, type Equal as aM, type Pretty as aN, data as aa, generatePath as ab, isRouteErrorResponse as ac, matchPath as ad, matchRoutes as ae, redirect as af, redirectDocument as ag, replace as ah, resolvePath as ai, type DataRouteMatch as aj, type DataRouteObject as ak, type Navigator as al, type PatchRoutesOnNavigationFunction as am, type PatchRoutesOnNavigationFunctionArgs as an, type RouteMatch as ao, type ClientActionFunctionArgs as ap, type ClientLoaderFunctionArgs as aq, type MetaArgs as ar, type MetaDescriptor as as, type PageLinkDescriptor as at, type HtmlLinkDescriptor as au, type LinkDescriptor as av, createBrowserHistory as aw, invariant as ax, createRouter as ay, ErrorResponseImpl as az, type ClientLoaderFunction as b, type LinksFunction as c, type RouteManifest as d, type LoaderFunctionArgs as e, type ActionFunctionArgs as f, type RelativeRoutingType as g, type Location as h, Action as i, type Path as j, type PathPattern as k, type PathMatch as l, type Params as m, type RouteObject as n, type Navigation as o, type RevalidationState as p, type Blocker as q, type StaticHandlerContext as r, type StaticHandler as s, type CreateStaticHandlerOptions as t, type IndexRouteObject as u, type NonIndexRouteObject as v, type RouterState as w, type GetScrollRestorationKeyFunction as x, type Fetcher as y, type NavigationStates as z };