react-router 0.0.0-experimental-e0b6ce9 → 0.0.0-experimental-de3b900
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/dist/development/browser-B4aBBnx8.d.ts +310 -0
- package/dist/development/browser-CN2w9Cbu.d.mts +310 -0
- package/dist/development/{chunk-4FI4BC6Y.mjs → chunk-5VDQAMOM.mjs} +181 -873
- package/dist/development/chunk-JEIV2ESS.js +1308 -0
- package/dist/development/{chunk-INO4IHBF.js → chunk-K3XLKYJI.js} +892 -409
- package/dist/development/{chunk-F6CT5MEB.mjs → chunk-OVO62ONG.mjs} +31 -314
- package/dist/development/chunk-UPBUMW2M.js +188 -0
- package/dist/development/dom-export.d.mts +51 -61
- package/dist/development/dom-export.d.ts +51 -60
- package/dist/development/dom-export.js +705 -23
- package/dist/development/dom-export.mjs +689 -14
- package/dist/{production/index-react-server-client-CYIi6gi0.d.mts → development/index-react-server-client-BOJoTiaG.d.ts} +76 -140
- package/dist/development/{index-react-server-client-CYIi6gi0.d.mts → index-react-server-client-CuQLmpku.d.mts} +76 -140
- package/dist/development/index-react-server-client.d.mts +2 -3
- package/dist/development/index-react-server-client.d.ts +2 -3
- package/dist/development/index-react-server-client.js +4 -4
- package/dist/development/index-react-server-client.mjs +2 -2
- package/dist/development/index-react-server.d.mts +1 -90
- package/dist/development/index-react-server.d.ts +1 -90
- package/dist/development/index-react-server.js +9 -188
- package/dist/development/index-react-server.mjs +9 -188
- package/dist/development/index.d.mts +21 -320
- package/dist/development/index.d.ts +21 -364
- package/dist/development/index.js +131 -977
- package/dist/development/index.mjs +5 -9
- package/dist/development/lib/types/internal.d.mts +2 -3
- package/dist/development/lib/types/internal.d.ts +2 -3
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/{production/register-DiOIlEq5.d.mts → development/register-BblEgJPm.d.mts} +7 -1
- package/dist/development/{register-DiOIlEq5.d.ts → register-D18raRVf.d.ts} +7 -1
- package/dist/development/{router-DWv6Clt-.d.mts → route-data-nQS6GSUI.d.mts} +1265 -932
- package/dist/development/{routeModules-DqotkItD.d.ts → routeModules-9wlxglVk.d.ts} +1047 -74
- package/dist/production/browser-B4aBBnx8.d.ts +310 -0
- package/dist/production/browser-CN2w9Cbu.d.mts +310 -0
- package/dist/production/{chunk-K7VXYOZD.js → chunk-63YB5VLY.js} +892 -409
- package/dist/production/chunk-IE722GR6.js +188 -0
- package/dist/production/{chunk-LKSLGWXX.mjs → chunk-U25H5FTL.mjs} +31 -314
- package/dist/production/chunk-VX4OHTGR.js +1308 -0
- package/dist/production/{chunk-52MYED7O.mjs → chunk-XOCFS75J.mjs} +181 -873
- package/dist/production/dom-export.d.mts +51 -61
- package/dist/production/dom-export.d.ts +51 -60
- package/dist/production/dom-export.js +705 -23
- package/dist/production/dom-export.mjs +689 -14
- package/dist/production/{index-react-server-client-ChBGplLn.d.ts → index-react-server-client-BOJoTiaG.d.ts} +76 -140
- package/dist/{development/index-react-server-client-ChBGplLn.d.ts → production/index-react-server-client-CuQLmpku.d.mts} +76 -140
- package/dist/production/index-react-server-client.d.mts +2 -3
- package/dist/production/index-react-server-client.d.ts +2 -3
- package/dist/production/index-react-server-client.js +4 -4
- package/dist/production/index-react-server-client.mjs +2 -2
- package/dist/production/index-react-server.d.mts +1 -90
- package/dist/production/index-react-server.d.ts +1 -90
- package/dist/production/index-react-server.js +9 -188
- package/dist/production/index-react-server.mjs +9 -188
- package/dist/production/index.d.mts +21 -320
- package/dist/production/index.d.ts +21 -364
- package/dist/production/index.js +131 -977
- package/dist/production/index.mjs +5 -9
- package/dist/production/lib/types/internal.d.mts +2 -3
- package/dist/production/lib/types/internal.d.ts +2 -3
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/{development/register-DiOIlEq5.d.mts → production/register-BblEgJPm.d.mts} +7 -1
- package/dist/production/{register-DiOIlEq5.d.ts → register-D18raRVf.d.ts} +7 -1
- package/dist/production/{router-DWv6Clt-.d.mts → route-data-nQS6GSUI.d.mts} +1265 -932
- package/dist/production/{routeModules-DqotkItD.d.ts → routeModules-9wlxglVk.d.ts} +1047 -74
- package/package.json +1 -1
- package/dist/development/browser-z32v5KVN.d.mts +0 -46
- package/dist/development/chunk-ITZFCV4J.js +0 -2092
- package/dist/development/instrumentation-BGrNA7uj.d.ts +0 -1122
- package/dist/development/routeModules-Cy4Xsfoi.d.mts +0 -483
- package/dist/production/browser-z32v5KVN.d.mts +0 -46
- package/dist/production/chunk-DASXXYNZ.js +0 -2092
- package/dist/production/instrumentation-BGrNA7uj.d.ts +0 -1122
- package/dist/production/routeModules-Cy4Xsfoi.d.mts +0 -483
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { ComponentType, ReactElement } from 'react';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Actions represent the type of change to a location value.
|
|
@@ -394,11 +395,6 @@ type DefaultContext = MiddlewareEnabled extends true ? Readonly<RouterContextPro
|
|
|
394
395
|
interface DataFunctionArgs<Context> {
|
|
395
396
|
/** 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. */
|
|
396
397
|
request: Request;
|
|
397
|
-
/**
|
|
398
|
-
* Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
|
|
399
|
-
* Mostly useful as a identifier to aggregate on for logging/tracing/etc.
|
|
400
|
-
*/
|
|
401
|
-
unstable_pattern: string;
|
|
402
398
|
/**
|
|
403
399
|
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
404
400
|
* @example
|
|
@@ -619,7 +615,7 @@ type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = Agn
|
|
|
619
615
|
* properties from framework-agnostic properties
|
|
620
616
|
*/
|
|
621
617
|
interface MapRoutePropertiesFunction {
|
|
622
|
-
(route:
|
|
618
|
+
(route: AgnosticRouteObject): {
|
|
623
619
|
hasErrorBoundary: boolean;
|
|
624
620
|
} & Record<string, any>;
|
|
625
621
|
}
|
|
@@ -1044,458 +1040,965 @@ declare class ErrorResponseImpl implements ErrorResponse {
|
|
|
1044
1040
|
*/
|
|
1045
1041
|
declare function isRouteErrorResponse(error: any): error is ErrorResponse;
|
|
1046
1042
|
|
|
1047
|
-
declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
|
|
1048
|
-
hasErrorBoundary: boolean;
|
|
1049
|
-
};
|
|
1050
|
-
declare const hydrationRouteProperties: (keyof RouteObject)[];
|
|
1051
1043
|
/**
|
|
1052
|
-
*
|
|
1044
|
+
* A Router instance manages all navigation and data loading/mutations
|
|
1053
1045
|
*/
|
|
1054
|
-
interface
|
|
1046
|
+
interface Router$1 {
|
|
1055
1047
|
/**
|
|
1056
|
-
*
|
|
1048
|
+
* @private
|
|
1049
|
+
* PRIVATE - DO NOT USE
|
|
1050
|
+
*
|
|
1051
|
+
* Return the basename for the router
|
|
1057
1052
|
*/
|
|
1058
|
-
basename
|
|
1053
|
+
get basename(): RouterInit["basename"];
|
|
1059
1054
|
/**
|
|
1060
|
-
*
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
*
|
|
1064
|
-
* navigation or fetcher call.
|
|
1055
|
+
* @private
|
|
1056
|
+
* PRIVATE - DO NOT USE
|
|
1057
|
+
*
|
|
1058
|
+
* Return the future config for the router
|
|
1065
1059
|
*/
|
|
1066
|
-
|
|
1060
|
+
get future(): FutureConfig;
|
|
1067
1061
|
/**
|
|
1068
|
-
*
|
|
1062
|
+
* @private
|
|
1063
|
+
* PRIVATE - DO NOT USE
|
|
1064
|
+
*
|
|
1065
|
+
* Return the current state of the router
|
|
1069
1066
|
*/
|
|
1070
|
-
|
|
1067
|
+
get state(): RouterState;
|
|
1071
1068
|
/**
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1069
|
+
* @private
|
|
1070
|
+
* PRIVATE - DO NOT USE
|
|
1071
|
+
*
|
|
1072
|
+
* Return the routes for this router instance
|
|
1074
1073
|
*/
|
|
1075
|
-
|
|
1074
|
+
get routes(): AgnosticDataRouteObject[];
|
|
1076
1075
|
/**
|
|
1077
|
-
*
|
|
1076
|
+
* @private
|
|
1077
|
+
* PRIVATE - DO NOT USE
|
|
1078
|
+
*
|
|
1079
|
+
* Return the window associated with the router
|
|
1078
1080
|
*/
|
|
1079
|
-
|
|
1081
|
+
get window(): RouterInit["window"];
|
|
1080
1082
|
/**
|
|
1081
|
-
*
|
|
1083
|
+
* @private
|
|
1084
|
+
* PRIVATE - DO NOT USE
|
|
1085
|
+
*
|
|
1086
|
+
* Initialize the router, including adding history listeners and kicking off
|
|
1087
|
+
* initial data fetches. Returns a function to cleanup listeners and abort
|
|
1088
|
+
* any in-progress loads
|
|
1082
1089
|
*/
|
|
1083
|
-
|
|
1090
|
+
initialize(): Router$1;
|
|
1084
1091
|
/**
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1087
|
-
* added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
|
|
1088
|
-
* mostly useful for observability such as wrapping navigations, fetches,
|
|
1089
|
-
* as well as route loaders/actions/middlewares with logging and/or performance
|
|
1090
|
-
* tracing.
|
|
1092
|
+
* @private
|
|
1093
|
+
* PRIVATE - DO NOT USE
|
|
1091
1094
|
*
|
|
1092
|
-
*
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
* });
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1098
|
-
* let logging = {
|
|
1099
|
-
* router({ instrument }) {
|
|
1100
|
-
* instrument({
|
|
1101
|
-
* navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
|
|
1102
|
-
* fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
|
|
1103
|
-
* });
|
|
1104
|
-
* },
|
|
1105
|
-
* route({ instrument, id }) {
|
|
1106
|
-
* instrument({
|
|
1107
|
-
* middleware: (impl, info) => logExecution(
|
|
1108
|
-
* `middleware ${info.request.url} (route ${id})`,
|
|
1109
|
-
* impl
|
|
1110
|
-
* ),
|
|
1111
|
-
* loader: (impl, info) => logExecution(
|
|
1112
|
-
* `loader ${info.request.url} (route ${id})`,
|
|
1113
|
-
* impl
|
|
1114
|
-
* ),
|
|
1115
|
-
* action: (impl, info) => logExecution(
|
|
1116
|
-
* `action ${info.request.url} (route ${id})`,
|
|
1117
|
-
* impl
|
|
1118
|
-
* ),
|
|
1119
|
-
* })
|
|
1120
|
-
* }
|
|
1121
|
-
* };
|
|
1122
|
-
*
|
|
1123
|
-
* async function logExecution(label: string, impl: () => Promise<void>) {
|
|
1124
|
-
* let start = performance.now();
|
|
1125
|
-
* console.log(`start ${label}`);
|
|
1126
|
-
* try {
|
|
1127
|
-
* await impl();
|
|
1128
|
-
* } finally {
|
|
1129
|
-
* let end = performance.now();
|
|
1130
|
-
* console.log(`end ${label} (${Math.round(end - start)}ms)`);
|
|
1131
|
-
* }
|
|
1132
|
-
* }
|
|
1133
|
-
* ```
|
|
1095
|
+
* Subscribe to router.state updates
|
|
1096
|
+
*
|
|
1097
|
+
* @param fn function to call with the new state
|
|
1134
1098
|
*/
|
|
1135
|
-
|
|
1099
|
+
subscribe(fn: RouterSubscriber): () => void;
|
|
1136
1100
|
/**
|
|
1137
|
-
*
|
|
1138
|
-
*
|
|
1101
|
+
* @private
|
|
1102
|
+
* PRIVATE - DO NOT USE
|
|
1103
|
+
*
|
|
1104
|
+
* Enable scroll restoration behavior in the router
|
|
1105
|
+
*
|
|
1106
|
+
* @param savedScrollPositions Object that will manage positions, in case
|
|
1107
|
+
* it's being restored from sessionStorage
|
|
1108
|
+
* @param getScrollPosition Function to get the active Y scroll position
|
|
1109
|
+
* @param getKey Function to get the key to use for restoration
|
|
1139
1110
|
*/
|
|
1140
|
-
|
|
1111
|
+
enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
|
|
1141
1112
|
/**
|
|
1142
|
-
*
|
|
1113
|
+
* @private
|
|
1114
|
+
* PRIVATE - DO NOT USE
|
|
1115
|
+
*
|
|
1116
|
+
* Navigate forward/backward in the history stack
|
|
1117
|
+
* @param to Delta to move in the history stack
|
|
1143
1118
|
*/
|
|
1144
|
-
|
|
1145
|
-
}
|
|
1146
|
-
/**
|
|
1147
|
-
* Create a new {@link DataRouter} that manages the application path using an
|
|
1148
|
-
* in-memory [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
|
1149
|
-
* stack. Useful for non-browser environments without a DOM API.
|
|
1150
|
-
*
|
|
1151
|
-
* @public
|
|
1152
|
-
* @category Data Routers
|
|
1153
|
-
* @mode data
|
|
1154
|
-
* @param routes Application routes
|
|
1155
|
-
* @param opts Options
|
|
1156
|
-
* @param {MemoryRouterOpts.basename} opts.basename n/a
|
|
1157
|
-
* @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
|
|
1158
|
-
* @param {MemoryRouterOpts.future} opts.future n/a
|
|
1159
|
-
* @param {MemoryRouterOpts.getContext} opts.getContext n/a
|
|
1160
|
-
* @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
|
|
1161
|
-
* @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
|
|
1162
|
-
* @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
|
|
1163
|
-
* @param {MemoryRouterOpts.unstable_instrumentations} opts.unstable_instrumentations n/a
|
|
1164
|
-
* @param {MemoryRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
|
|
1165
|
-
* @returns An initialized {@link DataRouter} to pass to {@link RouterProvider | `<RouterProvider>`}
|
|
1166
|
-
*/
|
|
1167
|
-
declare function createMemoryRouter(routes: RouteObject[], opts?: MemoryRouterOpts): Router;
|
|
1168
|
-
/**
|
|
1169
|
-
* Function signature for client side error handling for loader/actions errors
|
|
1170
|
-
* and rendering errors via `componentDidCatch`
|
|
1171
|
-
*/
|
|
1172
|
-
interface unstable_ClientOnErrorFunction {
|
|
1173
|
-
(error: unknown, errorInfo?: React.ErrorInfo): void;
|
|
1174
|
-
}
|
|
1175
|
-
/**
|
|
1176
|
-
* @category Types
|
|
1177
|
-
*/
|
|
1178
|
-
interface RouterProviderProps {
|
|
1119
|
+
navigate(to: number): Promise<void>;
|
|
1179
1120
|
/**
|
|
1180
|
-
*
|
|
1121
|
+
* Navigate to the given path
|
|
1122
|
+
* @param to Path to navigate to
|
|
1123
|
+
* @param opts Navigation options (method, submission, etc.)
|
|
1181
1124
|
*/
|
|
1182
|
-
|
|
1125
|
+
navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
|
|
1183
1126
|
/**
|
|
1184
|
-
*
|
|
1185
|
-
*
|
|
1127
|
+
* @private
|
|
1128
|
+
* PRIVATE - DO NOT USE
|
|
1186
1129
|
*
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1130
|
+
* Trigger a fetcher load/submission
|
|
1131
|
+
*
|
|
1132
|
+
* @param key Fetcher key
|
|
1133
|
+
* @param routeId Route that owns the fetcher
|
|
1134
|
+
* @param href href to fetch
|
|
1135
|
+
* @param opts Fetcher options, (method, submission, etc.)
|
|
1191
1136
|
*/
|
|
1192
|
-
|
|
1137
|
+
fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
|
|
1193
1138
|
/**
|
|
1194
|
-
*
|
|
1195
|
-
*
|
|
1196
|
-
* logging or reporting errors instead of the `ErrorBoundary` because it's not
|
|
1197
|
-
* subject to re-rendering and will only run one time per error.
|
|
1198
|
-
*
|
|
1199
|
-
* The `errorInfo` parameter is passed along from
|
|
1200
|
-
* [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
|
|
1201
|
-
* and is only present for render errors.
|
|
1139
|
+
* @private
|
|
1140
|
+
* PRIVATE - DO NOT USE
|
|
1202
1141
|
*
|
|
1203
|
-
*
|
|
1204
|
-
* <RouterProvider unstable_onError=(error, errorInfo) => {
|
|
1205
|
-
* console.error(error, errorInfo);
|
|
1206
|
-
* reportToErrorService(error, errorInfo);
|
|
1207
|
-
* }} />
|
|
1208
|
-
* ```
|
|
1142
|
+
* Trigger a revalidation of all current route loaders and fetcher loads
|
|
1209
1143
|
*/
|
|
1210
|
-
|
|
1211
|
-
}
|
|
1212
|
-
/**
|
|
1213
|
-
* Render the UI for the given {@link DataRouter}. This component should
|
|
1214
|
-
* typically be at the top of an app's element tree.
|
|
1215
|
-
*
|
|
1216
|
-
* ```tsx
|
|
1217
|
-
* import { createBrowserRouter } from "react-router";
|
|
1218
|
-
* import { RouterProvider } from "react-router/dom";
|
|
1219
|
-
* import { createRoot } from "react-dom/client";
|
|
1220
|
-
*
|
|
1221
|
-
* const router = createBrowserRouter(routes);
|
|
1222
|
-
* createRoot(document.getElementById("root")).render(
|
|
1223
|
-
* <RouterProvider router={router} />
|
|
1224
|
-
* );
|
|
1225
|
-
* ```
|
|
1226
|
-
*
|
|
1227
|
-
* <docs-info>Please note that this component is exported both from
|
|
1228
|
-
* `react-router` and `react-router/dom` with the only difference being that the
|
|
1229
|
-
* latter automatically wires up `react-dom`'s [`flushSync`](https://react.dev/reference/react-dom/flushSync)
|
|
1230
|
-
* implementation. You _almost always_ want to use the version from
|
|
1231
|
-
* `react-router/dom` unless you're running in a non-DOM environment.</docs-info>
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
* @public
|
|
1235
|
-
* @category Data Routers
|
|
1236
|
-
* @mode data
|
|
1237
|
-
* @param props Props
|
|
1238
|
-
* @param {RouterProviderProps.flushSync} props.flushSync n/a
|
|
1239
|
-
* @param {RouterProviderProps.unstable_onError} props.unstable_onError n/a
|
|
1240
|
-
* @param {RouterProviderProps.router} props.router n/a
|
|
1241
|
-
* @returns React element for the rendered router
|
|
1242
|
-
*/
|
|
1243
|
-
declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, unstable_onError, }: RouterProviderProps): React.ReactElement;
|
|
1244
|
-
/**
|
|
1245
|
-
* @category Types
|
|
1246
|
-
*/
|
|
1247
|
-
interface MemoryRouterProps {
|
|
1144
|
+
revalidate(): Promise<void>;
|
|
1248
1145
|
/**
|
|
1249
|
-
*
|
|
1146
|
+
* @private
|
|
1147
|
+
* PRIVATE - DO NOT USE
|
|
1148
|
+
*
|
|
1149
|
+
* Utility function to create an href for the given location
|
|
1150
|
+
* @param location
|
|
1250
1151
|
*/
|
|
1251
|
-
|
|
1152
|
+
createHref(location: Location | URL): string;
|
|
1252
1153
|
/**
|
|
1253
|
-
*
|
|
1154
|
+
* @private
|
|
1155
|
+
* PRIVATE - DO NOT USE
|
|
1156
|
+
*
|
|
1157
|
+
* Utility function to URL encode a destination path according to the internal
|
|
1158
|
+
* history implementation
|
|
1159
|
+
* @param to
|
|
1254
1160
|
*/
|
|
1255
|
-
|
|
1161
|
+
encodeLocation(to: To): Path;
|
|
1256
1162
|
/**
|
|
1257
|
-
*
|
|
1163
|
+
* @private
|
|
1164
|
+
* PRIVATE - DO NOT USE
|
|
1165
|
+
*
|
|
1166
|
+
* Get/create a fetcher for the given key
|
|
1167
|
+
* @param key
|
|
1258
1168
|
*/
|
|
1259
|
-
|
|
1169
|
+
getFetcher<TData = any>(key: string): Fetcher<TData>;
|
|
1260
1170
|
/**
|
|
1261
|
-
*
|
|
1171
|
+
* @internal
|
|
1172
|
+
* PRIVATE - DO NOT USE
|
|
1173
|
+
*
|
|
1174
|
+
* Reset the fetcher for a given key
|
|
1175
|
+
* @param key
|
|
1262
1176
|
*/
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
* A declarative {@link Router | `<Router>`} that stores all entries in memory.
|
|
1267
|
-
*
|
|
1268
|
-
* @public
|
|
1269
|
-
* @category Declarative Routers
|
|
1270
|
-
* @mode declarative
|
|
1271
|
-
* @param props Props
|
|
1272
|
-
* @param {MemoryRouterProps.basename} props.basename n/a
|
|
1273
|
-
* @param {MemoryRouterProps.children} props.children n/a
|
|
1274
|
-
* @param {MemoryRouterProps.initialEntries} props.initialEntries n/a
|
|
1275
|
-
* @param {MemoryRouterProps.initialIndex} props.initialIndex n/a
|
|
1276
|
-
* @returns A declarative in-memory {@link Router | `<Router>`} for client-side
|
|
1277
|
-
* routing.
|
|
1278
|
-
*/
|
|
1279
|
-
declare function MemoryRouter({ basename, children, initialEntries, initialIndex, }: MemoryRouterProps): React.ReactElement;
|
|
1280
|
-
/**
|
|
1281
|
-
* @category Types
|
|
1282
|
-
*/
|
|
1283
|
-
interface NavigateProps {
|
|
1177
|
+
resetFetcher(key: string, opts?: {
|
|
1178
|
+
reason?: unknown;
|
|
1179
|
+
}): void;
|
|
1284
1180
|
/**
|
|
1285
|
-
*
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
*
|
|
1290
|
-
* stack
|
|
1181
|
+
* @private
|
|
1182
|
+
* PRIVATE - DO NOT USE
|
|
1183
|
+
*
|
|
1184
|
+
* Delete the fetcher for a given key
|
|
1185
|
+
* @param key
|
|
1291
1186
|
*/
|
|
1292
|
-
|
|
1187
|
+
deleteFetcher(key: string): void;
|
|
1293
1188
|
/**
|
|
1294
|
-
*
|
|
1189
|
+
* @private
|
|
1190
|
+
* PRIVATE - DO NOT USE
|
|
1191
|
+
*
|
|
1192
|
+
* Cleanup listeners and abort any in-progress loads
|
|
1295
1193
|
*/
|
|
1296
|
-
|
|
1194
|
+
dispose(): void;
|
|
1297
1195
|
/**
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1196
|
+
* @private
|
|
1197
|
+
* PRIVATE - DO NOT USE
|
|
1198
|
+
*
|
|
1199
|
+
* Get a navigation blocker
|
|
1200
|
+
* @param key The identifier for the blocker
|
|
1201
|
+
* @param fn The blocker function implementation
|
|
1300
1202
|
*/
|
|
1301
|
-
|
|
1302
|
-
}
|
|
1303
|
-
/**
|
|
1304
|
-
* A component-based version of {@link useNavigate} to use in a
|
|
1305
|
-
* [`React.Component` class](https://react.dev/reference/react/Component) where
|
|
1306
|
-
* hooks cannot be used.
|
|
1307
|
-
*
|
|
1308
|
-
* It's recommended to avoid using this component in favor of {@link useNavigate}.
|
|
1309
|
-
*
|
|
1310
|
-
* @example
|
|
1311
|
-
* <Navigate to="/tasks" />
|
|
1312
|
-
*
|
|
1313
|
-
* @public
|
|
1314
|
-
* @category Components
|
|
1315
|
-
* @param props Props
|
|
1316
|
-
* @param {NavigateProps.relative} props.relative n/a
|
|
1317
|
-
* @param {NavigateProps.replace} props.replace n/a
|
|
1318
|
-
* @param {NavigateProps.state} props.state n/a
|
|
1319
|
-
* @param {NavigateProps.to} props.to n/a
|
|
1320
|
-
* @returns {void}
|
|
1321
|
-
*
|
|
1322
|
-
*/
|
|
1323
|
-
declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
|
|
1324
|
-
/**
|
|
1325
|
-
* @category Types
|
|
1326
|
-
*/
|
|
1327
|
-
interface OutletProps {
|
|
1203
|
+
getBlocker(key: string, fn: BlockerFunction): Blocker;
|
|
1328
1204
|
/**
|
|
1329
|
-
*
|
|
1330
|
-
*
|
|
1331
|
-
*
|
|
1332
|
-
* ```tsx
|
|
1333
|
-
* <Outlet context={myContextValue} />
|
|
1334
|
-
* ```
|
|
1205
|
+
* @private
|
|
1206
|
+
* PRIVATE - DO NOT USE
|
|
1335
1207
|
*
|
|
1336
|
-
*
|
|
1208
|
+
* Delete a navigation blocker
|
|
1209
|
+
* @param key The identifier for the blocker
|
|
1337
1210
|
*/
|
|
1338
|
-
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Renders the matching child route of a parent route or nothing if no child
|
|
1342
|
-
* route matches.
|
|
1343
|
-
*
|
|
1344
|
-
* @example
|
|
1345
|
-
* import { Outlet } from "react-router";
|
|
1346
|
-
*
|
|
1347
|
-
* export default function SomeParent() {
|
|
1348
|
-
* return (
|
|
1349
|
-
* <div>
|
|
1350
|
-
* <h1>Parent Content</h1>
|
|
1351
|
-
* <Outlet />
|
|
1352
|
-
* </div>
|
|
1353
|
-
* );
|
|
1354
|
-
* }
|
|
1355
|
-
*
|
|
1356
|
-
* @public
|
|
1357
|
-
* @category Components
|
|
1358
|
-
* @param props Props
|
|
1359
|
-
* @param {OutletProps.context} props.context n/a
|
|
1360
|
-
* @returns React element for the rendered outlet or `null` if no child route matches.
|
|
1361
|
-
*/
|
|
1362
|
-
declare function Outlet(props: OutletProps): React.ReactElement | null;
|
|
1363
|
-
/**
|
|
1364
|
-
* @category Types
|
|
1365
|
-
*/
|
|
1366
|
-
interface PathRouteProps {
|
|
1211
|
+
deleteBlocker(key: string): void;
|
|
1367
1212
|
/**
|
|
1368
|
-
*
|
|
1213
|
+
* @private
|
|
1214
|
+
* PRIVATE DO NOT USE
|
|
1215
|
+
*
|
|
1216
|
+
* Patch additional children routes into an existing parent route
|
|
1217
|
+
* @param routeId The parent route id or a callback function accepting `patch`
|
|
1218
|
+
* to perform batch patching
|
|
1219
|
+
* @param children The additional children routes
|
|
1220
|
+
* @param unstable_allowElementMutations Allow mutation or route elements on
|
|
1221
|
+
* existing routes. Intended for RSC-usage
|
|
1222
|
+
* only.
|
|
1369
1223
|
*/
|
|
1370
|
-
|
|
1224
|
+
patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
|
|
1371
1225
|
/**
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1226
|
+
* @private
|
|
1227
|
+
* PRIVATE - DO NOT USE
|
|
1228
|
+
*
|
|
1229
|
+
* HMR needs to pass in-flight route updates to React Router
|
|
1230
|
+
* TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
|
|
1374
1231
|
*/
|
|
1375
|
-
|
|
1232
|
+
_internalSetRoutes(routes: AgnosticRouteObject[]): void;
|
|
1376
1233
|
/**
|
|
1377
|
-
*
|
|
1234
|
+
* @private
|
|
1235
|
+
* PRIVATE - DO NOT USE
|
|
1236
|
+
*
|
|
1237
|
+
* Cause subscribers to re-render. This is used to force a re-render.
|
|
1378
1238
|
*/
|
|
1379
|
-
|
|
1239
|
+
_internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
|
|
1380
1240
|
/**
|
|
1381
|
-
*
|
|
1382
|
-
*
|
|
1383
|
-
*
|
|
1241
|
+
* @private
|
|
1242
|
+
* PRIVATE - DO NOT USE
|
|
1243
|
+
*
|
|
1244
|
+
* Internal fetch AbortControllers accessed by unit tests
|
|
1384
1245
|
*/
|
|
1385
|
-
|
|
1246
|
+
_internalFetchControllers: Map<string, AbortController>;
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* State maintained internally by the router. During a navigation, all states
|
|
1250
|
+
* reflect the "old" location unless otherwise noted.
|
|
1251
|
+
*/
|
|
1252
|
+
interface RouterState {
|
|
1386
1253
|
/**
|
|
1387
|
-
* The
|
|
1388
|
-
* See [`middleware`](../../start/data/route-object#middleware).
|
|
1254
|
+
* The action of the most recent navigation
|
|
1389
1255
|
*/
|
|
1390
|
-
|
|
1256
|
+
historyAction: Action;
|
|
1391
1257
|
/**
|
|
1392
|
-
* The
|
|
1393
|
-
* See [`loader`](../../start/data/route-object#loader).
|
|
1258
|
+
* The current location reflected by the router
|
|
1394
1259
|
*/
|
|
1395
|
-
|
|
1260
|
+
location: Location;
|
|
1396
1261
|
/**
|
|
1397
|
-
* The route
|
|
1398
|
-
* See [`action`](../../start/data/route-object#action).
|
|
1262
|
+
* The current set of route matches
|
|
1399
1263
|
*/
|
|
1400
|
-
|
|
1401
|
-
hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
|
|
1264
|
+
matches: AgnosticDataRouteMatch[];
|
|
1402
1265
|
/**
|
|
1403
|
-
*
|
|
1404
|
-
* See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
|
|
1266
|
+
* Tracks whether we've completed our initial data load
|
|
1405
1267
|
*/
|
|
1406
|
-
|
|
1268
|
+
initialized: boolean;
|
|
1407
1269
|
/**
|
|
1408
|
-
*
|
|
1270
|
+
* Current scroll position we should start at for a new view
|
|
1271
|
+
* - number -> scroll position to restore to
|
|
1272
|
+
* - false -> do not restore scroll at all (used during submissions/revalidations)
|
|
1273
|
+
* - null -> don't have a saved position, scroll to hash or top of page
|
|
1409
1274
|
*/
|
|
1410
|
-
|
|
1275
|
+
restoreScrollPosition: number | false | null;
|
|
1411
1276
|
/**
|
|
1412
|
-
*
|
|
1277
|
+
* Indicate whether this navigation should skip resetting the scroll position
|
|
1278
|
+
* if we are unable to restore the scroll position
|
|
1413
1279
|
*/
|
|
1414
|
-
|
|
1280
|
+
preventScrollReset: boolean;
|
|
1415
1281
|
/**
|
|
1416
|
-
*
|
|
1282
|
+
* Tracks the state of the current navigation
|
|
1417
1283
|
*/
|
|
1418
|
-
|
|
1284
|
+
navigation: Navigation;
|
|
1419
1285
|
/**
|
|
1420
|
-
*
|
|
1421
|
-
* Mutually exclusive with `Component`.
|
|
1286
|
+
* Tracks any in-progress revalidations
|
|
1422
1287
|
*/
|
|
1423
|
-
|
|
1288
|
+
revalidation: RevalidationState;
|
|
1424
1289
|
/**
|
|
1425
|
-
*
|
|
1426
|
-
* Mutually exclusive with `HydrateFallback`.
|
|
1290
|
+
* Data from the loaders for the current matches
|
|
1427
1291
|
*/
|
|
1428
|
-
|
|
1292
|
+
loaderData: RouteData;
|
|
1429
1293
|
/**
|
|
1430
|
-
*
|
|
1431
|
-
* Mutually exclusive with `ErrorBoundary`.
|
|
1294
|
+
* Data from the action for the current matches
|
|
1432
1295
|
*/
|
|
1433
|
-
|
|
1296
|
+
actionData: RouteData | null;
|
|
1434
1297
|
/**
|
|
1435
|
-
*
|
|
1436
|
-
* Mutually exclusive with `element`.
|
|
1298
|
+
* Errors caught from loaders for the current matches
|
|
1437
1299
|
*/
|
|
1438
|
-
|
|
1300
|
+
errors: RouteData | null;
|
|
1439
1301
|
/**
|
|
1440
|
-
*
|
|
1441
|
-
* Mutually exclusive with `hydrateFallbackElement`.
|
|
1302
|
+
* Map of current fetchers
|
|
1442
1303
|
*/
|
|
1443
|
-
|
|
1304
|
+
fetchers: Map<string, Fetcher>;
|
|
1444
1305
|
/**
|
|
1445
|
-
*
|
|
1446
|
-
* Mutually exclusive with `errorElement`.
|
|
1306
|
+
* Map of current blockers
|
|
1447
1307
|
*/
|
|
1448
|
-
|
|
1308
|
+
blockers: Map<string, Blocker>;
|
|
1449
1309
|
}
|
|
1450
1310
|
/**
|
|
1451
|
-
*
|
|
1311
|
+
* Data that can be passed into hydrate a Router from SSR
|
|
1452
1312
|
*/
|
|
1453
|
-
|
|
1313
|
+
type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Future flags to toggle new feature behavior
|
|
1316
|
+
*/
|
|
1317
|
+
interface FutureConfig {
|
|
1454
1318
|
}
|
|
1455
1319
|
/**
|
|
1456
|
-
*
|
|
1320
|
+
* Initialization options for createRouter
|
|
1457
1321
|
*/
|
|
1458
|
-
interface
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1322
|
+
interface RouterInit {
|
|
1323
|
+
routes: AgnosticRouteObject[];
|
|
1324
|
+
history: History;
|
|
1325
|
+
basename?: string;
|
|
1326
|
+
getContext?: () => MaybePromise<RouterContextProvider>;
|
|
1327
|
+
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
1328
|
+
future?: Partial<FutureConfig>;
|
|
1329
|
+
hydrationRouteProperties?: string[];
|
|
1330
|
+
hydrationData?: HydrationState;
|
|
1331
|
+
window?: Window;
|
|
1332
|
+
dataStrategy?: DataStrategyFunction;
|
|
1333
|
+
patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* State returned from a server-side query() call
|
|
1337
|
+
*/
|
|
1338
|
+
interface StaticHandlerContext {
|
|
1339
|
+
basename: Router$1["basename"];
|
|
1340
|
+
location: RouterState["location"];
|
|
1341
|
+
matches: RouterState["matches"];
|
|
1342
|
+
loaderData: RouterState["loaderData"];
|
|
1343
|
+
actionData: RouterState["actionData"];
|
|
1344
|
+
errors: RouterState["errors"];
|
|
1345
|
+
statusCode: number;
|
|
1346
|
+
loaderHeaders: Record<string, Headers>;
|
|
1347
|
+
actionHeaders: Record<string, Headers>;
|
|
1348
|
+
_deepestRenderedBoundaryId?: string | null;
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* A StaticHandler instance manages a singular SSR navigation/fetch event
|
|
1352
|
+
*/
|
|
1353
|
+
interface StaticHandler {
|
|
1354
|
+
dataRoutes: AgnosticDataRouteObject[];
|
|
1355
|
+
query(request: Request, opts?: {
|
|
1356
|
+
requestContext?: unknown;
|
|
1357
|
+
filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
|
|
1358
|
+
skipLoaderErrorBubbling?: boolean;
|
|
1359
|
+
skipRevalidation?: boolean;
|
|
1360
|
+
dataStrategy?: DataStrategyFunction<unknown>;
|
|
1361
|
+
generateMiddlewareResponse?: (query: (r: Request, args?: {
|
|
1362
|
+
filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
|
|
1363
|
+
}) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
1364
|
+
}): Promise<StaticHandlerContext | Response>;
|
|
1365
|
+
queryRoute(request: Request, opts?: {
|
|
1366
|
+
routeId?: string;
|
|
1367
|
+
requestContext?: unknown;
|
|
1368
|
+
dataStrategy?: DataStrategyFunction<unknown>;
|
|
1369
|
+
generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
|
|
1370
|
+
}): Promise<any>;
|
|
1371
|
+
}
|
|
1372
|
+
type ViewTransitionOpts = {
|
|
1373
|
+
currentLocation: Location;
|
|
1374
|
+
nextLocation: Location;
|
|
1375
|
+
};
|
|
1376
|
+
/**
|
|
1377
|
+
* Subscriber function signature for changes to router state
|
|
1378
|
+
*/
|
|
1379
|
+
interface RouterSubscriber {
|
|
1380
|
+
(state: RouterState, opts: {
|
|
1381
|
+
deletedFetchers: string[];
|
|
1382
|
+
viewTransitionOpts?: ViewTransitionOpts;
|
|
1383
|
+
flushSync: boolean;
|
|
1384
|
+
}): void;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Function signature for determining the key to be used in scroll restoration
|
|
1388
|
+
* for a given location
|
|
1389
|
+
*/
|
|
1390
|
+
interface GetScrollRestorationKeyFunction {
|
|
1391
|
+
(location: Location, matches: UIMatch[]): string | null;
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Function signature for determining the current scroll position
|
|
1395
|
+
*/
|
|
1396
|
+
interface GetScrollPositionFunction {
|
|
1397
|
+
(): number;
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* - "route": relative to the route hierarchy so `..` means remove all segments
|
|
1401
|
+
* of the current route even if it has many. For example, a `route("posts/:id")`
|
|
1402
|
+
* would have both `:id` and `posts` removed from the url.
|
|
1403
|
+
* - "path": relative to the pathname so `..` means remove one segment of the
|
|
1404
|
+
* pathname. For example, a `route("posts/:id")` would have only `:id` removed
|
|
1405
|
+
* from the url.
|
|
1406
|
+
*/
|
|
1407
|
+
type RelativeRoutingType = "route" | "path";
|
|
1408
|
+
type BaseNavigateOrFetchOptions = {
|
|
1409
|
+
preventScrollReset?: boolean;
|
|
1410
|
+
relative?: RelativeRoutingType;
|
|
1411
|
+
flushSync?: boolean;
|
|
1412
|
+
};
|
|
1413
|
+
type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
|
|
1414
|
+
replace?: boolean;
|
|
1415
|
+
state?: any;
|
|
1416
|
+
fromRouteId?: string;
|
|
1417
|
+
viewTransition?: boolean;
|
|
1418
|
+
};
|
|
1419
|
+
type BaseSubmissionOptions = {
|
|
1420
|
+
formMethod?: HTMLFormMethod;
|
|
1421
|
+
formEncType?: FormEncType;
|
|
1422
|
+
} & ({
|
|
1423
|
+
formData: FormData;
|
|
1424
|
+
body?: undefined;
|
|
1425
|
+
} | {
|
|
1426
|
+
formData?: undefined;
|
|
1427
|
+
body: any;
|
|
1428
|
+
});
|
|
1429
|
+
/**
|
|
1430
|
+
* Options for a navigate() call for a normal (non-submission) navigation
|
|
1431
|
+
*/
|
|
1432
|
+
type LinkNavigateOptions = BaseNavigateOptions;
|
|
1433
|
+
/**
|
|
1434
|
+
* Options for a navigate() call for a submission navigation
|
|
1435
|
+
*/
|
|
1436
|
+
type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
|
|
1437
|
+
/**
|
|
1438
|
+
* Options to pass to navigate() for a navigation
|
|
1439
|
+
*/
|
|
1440
|
+
type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
|
|
1441
|
+
/**
|
|
1442
|
+
* Options for a fetch() load
|
|
1443
|
+
*/
|
|
1444
|
+
type LoadFetchOptions = BaseNavigateOrFetchOptions;
|
|
1445
|
+
/**
|
|
1446
|
+
* Options for a fetch() submission
|
|
1447
|
+
*/
|
|
1448
|
+
type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
|
|
1449
|
+
/**
|
|
1450
|
+
* Options to pass to fetch()
|
|
1451
|
+
*/
|
|
1452
|
+
type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
|
|
1453
|
+
/**
|
|
1454
|
+
* Potential states for state.navigation
|
|
1455
|
+
*/
|
|
1456
|
+
type NavigationStates = {
|
|
1457
|
+
Idle: {
|
|
1458
|
+
state: "idle";
|
|
1459
|
+
location: undefined;
|
|
1460
|
+
formMethod: undefined;
|
|
1461
|
+
formAction: undefined;
|
|
1462
|
+
formEncType: undefined;
|
|
1463
|
+
formData: undefined;
|
|
1464
|
+
json: undefined;
|
|
1465
|
+
text: undefined;
|
|
1466
|
+
};
|
|
1467
|
+
Loading: {
|
|
1468
|
+
state: "loading";
|
|
1469
|
+
location: Location;
|
|
1470
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
1471
|
+
formAction: Submission["formAction"] | undefined;
|
|
1472
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
1473
|
+
formData: Submission["formData"] | undefined;
|
|
1474
|
+
json: Submission["json"] | undefined;
|
|
1475
|
+
text: Submission["text"] | undefined;
|
|
1476
|
+
};
|
|
1477
|
+
Submitting: {
|
|
1478
|
+
state: "submitting";
|
|
1479
|
+
location: Location;
|
|
1480
|
+
formMethod: Submission["formMethod"];
|
|
1481
|
+
formAction: Submission["formAction"];
|
|
1482
|
+
formEncType: Submission["formEncType"];
|
|
1483
|
+
formData: Submission["formData"];
|
|
1484
|
+
json: Submission["json"];
|
|
1485
|
+
text: Submission["text"];
|
|
1486
|
+
};
|
|
1487
|
+
};
|
|
1488
|
+
type Navigation = NavigationStates[keyof NavigationStates];
|
|
1489
|
+
type RevalidationState = "idle" | "loading";
|
|
1490
|
+
/**
|
|
1491
|
+
* Potential states for fetchers
|
|
1492
|
+
*/
|
|
1493
|
+
type FetcherStates<TData = any> = {
|
|
1494
|
+
/**
|
|
1495
|
+
* The fetcher is not calling a loader or action
|
|
1496
|
+
*
|
|
1497
|
+
* ```tsx
|
|
1498
|
+
* fetcher.state === "idle"
|
|
1499
|
+
* ```
|
|
1500
|
+
*/
|
|
1501
|
+
Idle: {
|
|
1502
|
+
state: "idle";
|
|
1503
|
+
formMethod: undefined;
|
|
1504
|
+
formAction: undefined;
|
|
1505
|
+
formEncType: undefined;
|
|
1506
|
+
text: undefined;
|
|
1507
|
+
formData: undefined;
|
|
1508
|
+
json: undefined;
|
|
1509
|
+
/**
|
|
1510
|
+
* If the fetcher has never been called, this will be undefined.
|
|
1511
|
+
*/
|
|
1512
|
+
data: TData | undefined;
|
|
1513
|
+
};
|
|
1514
|
+
/**
|
|
1515
|
+
* The fetcher is loading data from a {@link LoaderFunction | loader} from a
|
|
1516
|
+
* call to {@link FetcherWithComponents.load | `fetcher.load`}.
|
|
1517
|
+
*
|
|
1518
|
+
* ```tsx
|
|
1519
|
+
* // somewhere
|
|
1520
|
+
* <button onClick={() => fetcher.load("/some/route") }>Load</button>
|
|
1521
|
+
*
|
|
1522
|
+
* // the state will update
|
|
1523
|
+
* fetcher.state === "loading"
|
|
1524
|
+
* ```
|
|
1525
|
+
*/
|
|
1526
|
+
Loading: {
|
|
1527
|
+
state: "loading";
|
|
1528
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
1529
|
+
formAction: Submission["formAction"] | undefined;
|
|
1530
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
1531
|
+
text: Submission["text"] | undefined;
|
|
1532
|
+
formData: Submission["formData"] | undefined;
|
|
1533
|
+
json: Submission["json"] | undefined;
|
|
1534
|
+
data: TData | undefined;
|
|
1535
|
+
};
|
|
1536
|
+
/**
|
|
1537
|
+
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`}.
|
|
1538
|
+
|
|
1539
|
+
```tsx
|
|
1540
|
+
// somewhere
|
|
1541
|
+
<input
|
|
1542
|
+
onChange={e => {
|
|
1543
|
+
fetcher.submit(event.currentTarget.form, { method: "post" });
|
|
1544
|
+
}}
|
|
1545
|
+
/>
|
|
1546
|
+
|
|
1547
|
+
// the state will update
|
|
1548
|
+
fetcher.state === "submitting"
|
|
1549
|
+
|
|
1550
|
+
// and formData will be available
|
|
1551
|
+
fetcher.formData
|
|
1552
|
+
```
|
|
1553
|
+
*/
|
|
1554
|
+
Submitting: {
|
|
1555
|
+
state: "submitting";
|
|
1556
|
+
formMethod: Submission["formMethod"];
|
|
1557
|
+
formAction: Submission["formAction"];
|
|
1558
|
+
formEncType: Submission["formEncType"];
|
|
1559
|
+
text: Submission["text"];
|
|
1560
|
+
formData: Submission["formData"];
|
|
1561
|
+
json: Submission["json"];
|
|
1562
|
+
data: TData | undefined;
|
|
1563
|
+
};
|
|
1564
|
+
};
|
|
1565
|
+
type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
|
|
1566
|
+
interface BlockerBlocked {
|
|
1567
|
+
state: "blocked";
|
|
1568
|
+
reset: () => void;
|
|
1569
|
+
proceed: () => void;
|
|
1570
|
+
location: Location;
|
|
1571
|
+
}
|
|
1572
|
+
interface BlockerUnblocked {
|
|
1573
|
+
state: "unblocked";
|
|
1574
|
+
reset: undefined;
|
|
1575
|
+
proceed: undefined;
|
|
1576
|
+
location: undefined;
|
|
1577
|
+
}
|
|
1578
|
+
interface BlockerProceeding {
|
|
1579
|
+
state: "proceeding";
|
|
1580
|
+
reset: undefined;
|
|
1581
|
+
proceed: undefined;
|
|
1582
|
+
location: Location;
|
|
1583
|
+
}
|
|
1584
|
+
type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
|
|
1585
|
+
type BlockerFunction = (args: {
|
|
1586
|
+
currentLocation: Location;
|
|
1587
|
+
nextLocation: Location;
|
|
1588
|
+
historyAction: Action;
|
|
1589
|
+
}) => boolean;
|
|
1590
|
+
declare const IDLE_NAVIGATION: NavigationStates["Idle"];
|
|
1591
|
+
declare const IDLE_FETCHER: FetcherStates["Idle"];
|
|
1592
|
+
declare const IDLE_BLOCKER: BlockerUnblocked;
|
|
1593
|
+
/**
|
|
1594
|
+
* Create a router and listen to history POP navigations
|
|
1595
|
+
*/
|
|
1596
|
+
declare function createRouter(init: RouterInit): Router$1;
|
|
1597
|
+
interface CreateStaticHandlerOptions {
|
|
1598
|
+
basename?: string;
|
|
1599
|
+
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
1600
|
+
future?: {};
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
|
|
1604
|
+
hasErrorBoundary: boolean;
|
|
1605
|
+
};
|
|
1606
|
+
declare const hydrationRouteProperties: (keyof RouteObject)[];
|
|
1607
|
+
/**
|
|
1608
|
+
* @category Data Routers
|
|
1609
|
+
*/
|
|
1610
|
+
interface MemoryRouterOpts {
|
|
1611
|
+
/**
|
|
1612
|
+
* Basename path for the application.
|
|
1613
|
+
*/
|
|
1614
|
+
basename?: string;
|
|
1615
|
+
/**
|
|
1616
|
+
* A function that returns an {@link RouterContextProvider} instance
|
|
1617
|
+
* which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
|
|
1618
|
+
* [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
|
|
1619
|
+
* This function is called to generate a fresh `context` instance on each
|
|
1620
|
+
* navigation or fetcher call.
|
|
1621
|
+
*/
|
|
1622
|
+
getContext?: RouterInit["getContext"];
|
|
1623
|
+
/**
|
|
1624
|
+
* Future flags to enable for the router.
|
|
1625
|
+
*/
|
|
1626
|
+
future?: Partial<FutureConfig>;
|
|
1627
|
+
/**
|
|
1628
|
+
* Hydration data to initialize the router with if you have already performed
|
|
1629
|
+
* data loading on the server.
|
|
1630
|
+
*/
|
|
1631
|
+
hydrationData?: HydrationState;
|
|
1632
|
+
/**
|
|
1633
|
+
* Initial entries in the in-memory history stack
|
|
1634
|
+
*/
|
|
1635
|
+
initialEntries?: InitialEntry[];
|
|
1636
|
+
/**
|
|
1637
|
+
* Index of `initialEntries` the application should initialize to
|
|
1638
|
+
*/
|
|
1639
|
+
initialIndex?: number;
|
|
1640
|
+
/**
|
|
1641
|
+
* Override the default data strategy of loading in parallel.
|
|
1642
|
+
* Only intended for advanced usage.
|
|
1643
|
+
*/
|
|
1644
|
+
dataStrategy?: DataStrategyFunction;
|
|
1645
|
+
/**
|
|
1646
|
+
* Lazily define portions of the route tree on navigations.
|
|
1647
|
+
*/
|
|
1648
|
+
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Create a new {@link DataRouter} that manages the application path using an
|
|
1652
|
+
* in-memory [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
|
1653
|
+
* stack. Useful for non-browser environments without a DOM API.
|
|
1654
|
+
*
|
|
1655
|
+
* @public
|
|
1656
|
+
* @category Data Routers
|
|
1657
|
+
* @mode data
|
|
1658
|
+
* @param routes Application routes
|
|
1659
|
+
* @param opts Options
|
|
1660
|
+
* @param {MemoryRouterOpts.basename} opts.basename n/a
|
|
1661
|
+
* @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
|
|
1662
|
+
* @param {MemoryRouterOpts.future} opts.future n/a
|
|
1663
|
+
* @param {MemoryRouterOpts.getContext} opts.getContext n/a
|
|
1664
|
+
* @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
|
|
1665
|
+
* @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
|
|
1666
|
+
* @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
|
|
1667
|
+
* @param {MemoryRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
|
|
1668
|
+
* @returns An initialized {@link DataRouter} to pass to {@link RouterProvider | `<RouterProvider>`}
|
|
1669
|
+
*/
|
|
1670
|
+
declare function createMemoryRouter(routes: RouteObject[], opts?: MemoryRouterOpts): Router$1;
|
|
1671
|
+
/**
|
|
1672
|
+
* Function signature for client side error handling for loader/actions errors
|
|
1673
|
+
* and rendering errors via `componentDidCatch`
|
|
1674
|
+
*/
|
|
1675
|
+
interface unstable_ClientOnErrorFunction {
|
|
1676
|
+
(error: unknown, errorInfo?: React.ErrorInfo): void;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* @category Types
|
|
1680
|
+
*/
|
|
1681
|
+
interface RouterProviderProps {
|
|
1682
|
+
/**
|
|
1683
|
+
* The {@link DataRouter} instance to use for navigation and data fetching.
|
|
1684
|
+
*/
|
|
1685
|
+
router: Router$1;
|
|
1686
|
+
/**
|
|
1687
|
+
* The [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
|
|
1688
|
+
* implementation to use for flushing updates.
|
|
1689
|
+
*
|
|
1690
|
+
* You usually don't have to worry about this:
|
|
1691
|
+
* - The `RouterProvider` exported from `react-router/dom` handles this internally for you
|
|
1692
|
+
* - If you are rendering in a non-DOM environment, you can import
|
|
1693
|
+
* `RouterProvider` from `react-router` and ignore this prop
|
|
1694
|
+
*/
|
|
1695
|
+
flushSync?: (fn: () => unknown) => undefined;
|
|
1696
|
+
/**
|
|
1697
|
+
* An error handler function that will be called for any loader/action/render
|
|
1698
|
+
* errors that are encountered in your application. This is useful for
|
|
1699
|
+
* logging or reporting errors instead of the `ErrorBoundary` because it's not
|
|
1700
|
+
* subject to re-rendering and will only run one time per error.
|
|
1701
|
+
*
|
|
1702
|
+
* The `errorInfo` parameter is passed along from
|
|
1703
|
+
* [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
|
|
1704
|
+
* and is only present for render errors.
|
|
1705
|
+
*
|
|
1706
|
+
* ```tsx
|
|
1707
|
+
* <RouterProvider unstable_onError=(error, errorInfo) => {
|
|
1708
|
+
* console.error(error, errorInfo);
|
|
1709
|
+
* reportToErrorService(error, errorInfo);
|
|
1710
|
+
* }} />
|
|
1711
|
+
* ```
|
|
1712
|
+
*/
|
|
1713
|
+
unstable_onError?: unstable_ClientOnErrorFunction;
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Render the UI for the given {@link DataRouter}. This component should
|
|
1717
|
+
* typically be at the top of an app's element tree.
|
|
1718
|
+
*
|
|
1719
|
+
* ```tsx
|
|
1720
|
+
* import { createBrowserRouter } from "react-router";
|
|
1721
|
+
* import { RouterProvider } from "react-router/dom";
|
|
1722
|
+
* import { createRoot } from "react-dom/client";
|
|
1723
|
+
*
|
|
1724
|
+
* const router = createBrowserRouter(routes);
|
|
1725
|
+
* createRoot(document.getElementById("root")).render(
|
|
1726
|
+
* <RouterProvider router={router} />
|
|
1727
|
+
* );
|
|
1728
|
+
* ```
|
|
1729
|
+
*
|
|
1730
|
+
* <docs-info>Please note that this component is exported both from
|
|
1731
|
+
* `react-router` and `react-router/dom` with the only difference being that the
|
|
1732
|
+
* latter automatically wires up `react-dom`'s [`flushSync`](https://react.dev/reference/react-dom/flushSync)
|
|
1733
|
+
* implementation. You _almost always_ want to use the version from
|
|
1734
|
+
* `react-router/dom` unless you're running in a non-DOM environment.</docs-info>
|
|
1735
|
+
*
|
|
1736
|
+
*
|
|
1737
|
+
* @public
|
|
1738
|
+
* @category Data Routers
|
|
1739
|
+
* @mode data
|
|
1740
|
+
* @param props Props
|
|
1741
|
+
* @param {RouterProviderProps.flushSync} props.flushSync n/a
|
|
1742
|
+
* @param {RouterProviderProps.unstable_onError} props.unstable_onError n/a
|
|
1743
|
+
* @param {RouterProviderProps.router} props.router n/a
|
|
1744
|
+
* @returns React element for the rendered router
|
|
1745
|
+
*/
|
|
1746
|
+
declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, unstable_onError, }: RouterProviderProps): React.ReactElement;
|
|
1747
|
+
/**
|
|
1748
|
+
* @category Types
|
|
1749
|
+
*/
|
|
1750
|
+
interface MemoryRouterProps {
|
|
1751
|
+
/**
|
|
1752
|
+
* Application basename
|
|
1753
|
+
*/
|
|
1754
|
+
basename?: string;
|
|
1755
|
+
/**
|
|
1756
|
+
* Nested {@link Route} elements describing the route tree
|
|
1757
|
+
*/
|
|
1758
|
+
children?: React.ReactNode;
|
|
1759
|
+
/**
|
|
1760
|
+
* Initial entries in the in-memory history stack
|
|
1761
|
+
*/
|
|
1762
|
+
initialEntries?: InitialEntry[];
|
|
1763
|
+
/**
|
|
1764
|
+
* Index of `initialEntries` the application should initialize to
|
|
1765
|
+
*/
|
|
1766
|
+
initialIndex?: number;
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
* A declarative {@link Router | `<Router>`} that stores all entries in memory.
|
|
1770
|
+
*
|
|
1771
|
+
* @public
|
|
1772
|
+
* @category Declarative Routers
|
|
1773
|
+
* @mode declarative
|
|
1774
|
+
* @param props Props
|
|
1775
|
+
* @param {MemoryRouterProps.basename} props.basename n/a
|
|
1776
|
+
* @param {MemoryRouterProps.children} props.children n/a
|
|
1777
|
+
* @param {MemoryRouterProps.initialEntries} props.initialEntries n/a
|
|
1778
|
+
* @param {MemoryRouterProps.initialIndex} props.initialIndex n/a
|
|
1779
|
+
* @returns A declarative in-memory {@link Router | `<Router>`} for client-side
|
|
1780
|
+
* routing.
|
|
1781
|
+
*/
|
|
1782
|
+
declare function MemoryRouter({ basename, children, initialEntries, initialIndex, }: MemoryRouterProps): React.ReactElement;
|
|
1783
|
+
/**
|
|
1784
|
+
* @category Types
|
|
1785
|
+
*/
|
|
1786
|
+
interface NavigateProps {
|
|
1787
|
+
/**
|
|
1788
|
+
* The path to navigate to. This can be a string or a {@link Path} object
|
|
1789
|
+
*/
|
|
1790
|
+
to: To;
|
|
1791
|
+
/**
|
|
1792
|
+
* Whether to replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
|
1793
|
+
* stack
|
|
1794
|
+
*/
|
|
1795
|
+
replace?: boolean;
|
|
1796
|
+
/**
|
|
1797
|
+
* State to pass to the new {@link Location} to store in [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state).
|
|
1798
|
+
*/
|
|
1799
|
+
state?: any;
|
|
1800
|
+
/**
|
|
1801
|
+
* How to interpret relative routing in the `to` prop.
|
|
1802
|
+
* See {@link RelativeRoutingType}.
|
|
1803
|
+
*/
|
|
1804
|
+
relative?: RelativeRoutingType;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* A component-based version of {@link useNavigate} to use in a
|
|
1808
|
+
* [`React.Component` class](https://react.dev/reference/react/Component) where
|
|
1809
|
+
* hooks cannot be used.
|
|
1810
|
+
*
|
|
1811
|
+
* It's recommended to avoid using this component in favor of {@link useNavigate}.
|
|
1812
|
+
*
|
|
1813
|
+
* @example
|
|
1814
|
+
* <Navigate to="/tasks" />
|
|
1815
|
+
*
|
|
1816
|
+
* @public
|
|
1817
|
+
* @category Components
|
|
1818
|
+
* @param props Props
|
|
1819
|
+
* @param {NavigateProps.relative} props.relative n/a
|
|
1820
|
+
* @param {NavigateProps.replace} props.replace n/a
|
|
1821
|
+
* @param {NavigateProps.state} props.state n/a
|
|
1822
|
+
* @param {NavigateProps.to} props.to n/a
|
|
1823
|
+
* @returns {void}
|
|
1824
|
+
*
|
|
1825
|
+
*/
|
|
1826
|
+
declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
|
|
1827
|
+
/**
|
|
1828
|
+
* @category Types
|
|
1829
|
+
*/
|
|
1830
|
+
interface OutletProps {
|
|
1831
|
+
/**
|
|
1832
|
+
* Provides a context value to the element tree below the outlet. Use when
|
|
1833
|
+
* the parent route needs to provide values to child routes.
|
|
1834
|
+
*
|
|
1835
|
+
* ```tsx
|
|
1836
|
+
* <Outlet context={myContextValue} />
|
|
1837
|
+
* ```
|
|
1838
|
+
*
|
|
1839
|
+
* Access the context with {@link useOutletContext}.
|
|
1840
|
+
*/
|
|
1841
|
+
context?: unknown;
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Renders the matching child route of a parent route or nothing if no child
|
|
1845
|
+
* route matches.
|
|
1846
|
+
*
|
|
1847
|
+
* @example
|
|
1848
|
+
* import { Outlet } from "react-router";
|
|
1849
|
+
*
|
|
1850
|
+
* export default function SomeParent() {
|
|
1851
|
+
* return (
|
|
1852
|
+
* <div>
|
|
1853
|
+
* <h1>Parent Content</h1>
|
|
1854
|
+
* <Outlet />
|
|
1855
|
+
* </div>
|
|
1856
|
+
* );
|
|
1857
|
+
* }
|
|
1858
|
+
*
|
|
1859
|
+
* @public
|
|
1860
|
+
* @category Components
|
|
1861
|
+
* @param props Props
|
|
1862
|
+
* @param {OutletProps.context} props.context n/a
|
|
1863
|
+
* @returns React element for the rendered outlet or `null` if no child route matches.
|
|
1864
|
+
*/
|
|
1865
|
+
declare function Outlet(props: OutletProps): React.ReactElement | null;
|
|
1866
|
+
/**
|
|
1867
|
+
* @category Types
|
|
1868
|
+
*/
|
|
1869
|
+
interface PathRouteProps {
|
|
1870
|
+
/**
|
|
1871
|
+
* Whether the path should be case-sensitive. Defaults to `false`.
|
|
1872
|
+
*/
|
|
1873
|
+
caseSensitive?: NonIndexRouteObject["caseSensitive"];
|
|
1874
|
+
/**
|
|
1875
|
+
* The path pattern to match. If unspecified or empty, then this becomes a
|
|
1876
|
+
* layout route.
|
|
1877
|
+
*/
|
|
1878
|
+
path?: NonIndexRouteObject["path"];
|
|
1879
|
+
/**
|
|
1880
|
+
* The unique identifier for this route (for use with {@link DataRouter}s)
|
|
1881
|
+
*/
|
|
1882
|
+
id?: NonIndexRouteObject["id"];
|
|
1883
|
+
/**
|
|
1884
|
+
* A function that returns a promise that resolves to the route object.
|
|
1885
|
+
* Used for code-splitting routes.
|
|
1886
|
+
* See [`lazy`](../../start/data/route-object#lazy).
|
|
1887
|
+
*/
|
|
1888
|
+
lazy?: LazyRouteFunction<NonIndexRouteObject>;
|
|
1889
|
+
/**
|
|
1890
|
+
* The route middleware.
|
|
1891
|
+
* See [`middleware`](../../start/data/route-object#middleware).
|
|
1892
|
+
*/
|
|
1893
|
+
middleware?: NonIndexRouteObject["middleware"];
|
|
1894
|
+
/**
|
|
1895
|
+
* The route loader.
|
|
1896
|
+
* See [`loader`](../../start/data/route-object#loader).
|
|
1897
|
+
*/
|
|
1898
|
+
loader?: NonIndexRouteObject["loader"];
|
|
1899
|
+
/**
|
|
1900
|
+
* The route action.
|
|
1901
|
+
* See [`action`](../../start/data/route-object#action).
|
|
1902
|
+
*/
|
|
1903
|
+
action?: NonIndexRouteObject["action"];
|
|
1904
|
+
hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
|
|
1905
|
+
/**
|
|
1906
|
+
* The route shouldRevalidate function.
|
|
1907
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
|
|
1908
|
+
*/
|
|
1909
|
+
shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
|
|
1910
|
+
/**
|
|
1911
|
+
* The route handle.
|
|
1912
|
+
*/
|
|
1913
|
+
handle?: NonIndexRouteObject["handle"];
|
|
1914
|
+
/**
|
|
1915
|
+
* Whether this is an index route.
|
|
1916
|
+
*/
|
|
1917
|
+
index?: false;
|
|
1918
|
+
/**
|
|
1919
|
+
* Child Route components
|
|
1920
|
+
*/
|
|
1921
|
+
children?: React.ReactNode;
|
|
1922
|
+
/**
|
|
1923
|
+
* The React element to render when this Route matches.
|
|
1924
|
+
* Mutually exclusive with `Component`.
|
|
1925
|
+
*/
|
|
1926
|
+
element?: React.ReactNode | null;
|
|
1927
|
+
/**
|
|
1928
|
+
* The React element to render while this router is loading data.
|
|
1929
|
+
* Mutually exclusive with `HydrateFallback`.
|
|
1930
|
+
*/
|
|
1931
|
+
hydrateFallbackElement?: React.ReactNode | null;
|
|
1932
|
+
/**
|
|
1933
|
+
* The React element to render at this route if an error occurs.
|
|
1934
|
+
* Mutually exclusive with `ErrorBoundary`.
|
|
1935
|
+
*/
|
|
1936
|
+
errorElement?: React.ReactNode | null;
|
|
1937
|
+
/**
|
|
1938
|
+
* The React Component to render when this route matches.
|
|
1939
|
+
* Mutually exclusive with `element`.
|
|
1940
|
+
*/
|
|
1941
|
+
Component?: React.ComponentType | null;
|
|
1942
|
+
/**
|
|
1943
|
+
* The React Component to render while this router is loading data.
|
|
1944
|
+
* Mutually exclusive with `hydrateFallbackElement`.
|
|
1945
|
+
*/
|
|
1946
|
+
HydrateFallback?: React.ComponentType | null;
|
|
1947
|
+
/**
|
|
1948
|
+
* The React Component to render at this route if an error occurs.
|
|
1949
|
+
* Mutually exclusive with `errorElement`.
|
|
1950
|
+
*/
|
|
1951
|
+
ErrorBoundary?: React.ComponentType | null;
|
|
1952
|
+
}
|
|
1953
|
+
/**
|
|
1954
|
+
* @category Types
|
|
1955
|
+
*/
|
|
1956
|
+
interface LayoutRouteProps extends PathRouteProps {
|
|
1957
|
+
}
|
|
1958
|
+
/**
|
|
1959
|
+
* @category Types
|
|
1960
|
+
*/
|
|
1961
|
+
interface IndexRouteProps {
|
|
1962
|
+
/**
|
|
1963
|
+
* Whether the path should be case-sensitive. Defaults to `false`.
|
|
1964
|
+
*/
|
|
1965
|
+
caseSensitive?: IndexRouteObject["caseSensitive"];
|
|
1966
|
+
/**
|
|
1967
|
+
* The path pattern to match. If unspecified or empty, then this becomes a
|
|
1968
|
+
* layout route.
|
|
1969
|
+
*/
|
|
1970
|
+
path?: IndexRouteObject["path"];
|
|
1971
|
+
/**
|
|
1972
|
+
* The unique identifier for this route (for use with {@link DataRouter}s)
|
|
1973
|
+
*/
|
|
1974
|
+
id?: IndexRouteObject["id"];
|
|
1975
|
+
/**
|
|
1976
|
+
* A function that returns a promise that resolves to the route object.
|
|
1977
|
+
* Used for code-splitting routes.
|
|
1978
|
+
* See [`lazy`](../../start/data/route-object#lazy).
|
|
1979
|
+
*/
|
|
1980
|
+
lazy?: LazyRouteFunction<IndexRouteObject>;
|
|
1981
|
+
/**
|
|
1982
|
+
* The route middleware.
|
|
1983
|
+
* See [`middleware`](../../start/data/route-object#middleware).
|
|
1984
|
+
*/
|
|
1985
|
+
middleware?: IndexRouteObject["middleware"];
|
|
1986
|
+
/**
|
|
1987
|
+
* The route loader.
|
|
1988
|
+
* See [`loader`](../../start/data/route-object#loader).
|
|
1989
|
+
*/
|
|
1990
|
+
loader?: IndexRouteObject["loader"];
|
|
1991
|
+
/**
|
|
1992
|
+
* The route action.
|
|
1993
|
+
* See [`action`](../../start/data/route-object#action).
|
|
1994
|
+
*/
|
|
1995
|
+
action?: IndexRouteObject["action"];
|
|
1996
|
+
hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
|
|
1997
|
+
/**
|
|
1998
|
+
* The route shouldRevalidate function.
|
|
1999
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
|
|
2000
|
+
*/
|
|
2001
|
+
shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
|
|
1499
2002
|
/**
|
|
1500
2003
|
* The route handle.
|
|
1501
2004
|
*/
|
|
@@ -1650,7 +2153,7 @@ interface RouterProps {
|
|
|
1650
2153
|
* @returns React element for the rendered router or `null` if the location does
|
|
1651
2154
|
* not match the {@link props.basename}
|
|
1652
2155
|
*/
|
|
1653
|
-
declare function Router
|
|
2156
|
+
declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, }: RouterProps): React.ReactElement | null;
|
|
1654
2157
|
/**
|
|
1655
2158
|
* @category Types
|
|
1656
2159
|
*/
|
|
@@ -1676,7 +2179,7 @@ interface RoutesProps {
|
|
|
1676
2179
|
* <Routes>
|
|
1677
2180
|
* <Route index element={<StepOne />} />
|
|
1678
2181
|
* <Route path="step-2" element={<StepTwo />} />
|
|
1679
|
-
* <Route path="step-3" element={<StepThree />}
|
|
2182
|
+
* <Route path="step-3" element={<StepThree />} />
|
|
1680
2183
|
* </Routes>
|
|
1681
2184
|
*
|
|
1682
2185
|
* @public
|
|
@@ -1995,7 +2498,7 @@ interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
|
|
|
1995
2498
|
type PatchRoutesOnNavigationFunctionArgs = AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;
|
|
1996
2499
|
type PatchRoutesOnNavigationFunction = AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;
|
|
1997
2500
|
interface DataRouterContextObject extends Omit<NavigationContextObject, "future"> {
|
|
1998
|
-
router: Router;
|
|
2501
|
+
router: Router$1;
|
|
1999
2502
|
staticContext?: StaticHandlerContext;
|
|
2000
2503
|
unstable_onError?: unstable_ClientOnErrorFunction;
|
|
2001
2504
|
}
|
|
@@ -2060,646 +2563,476 @@ interface RouteContextObject {
|
|
|
2060
2563
|
outlet: React.ReactElement | null;
|
|
2061
2564
|
matches: RouteMatch[];
|
|
2062
2565
|
isDataRoute: boolean;
|
|
2063
|
-
}
|
|
2064
|
-
declare const RouteContext: React.Context<RouteContextObject>;
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
type
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
}
|
|
2080
|
-
type ReadonlyRequest = {
|
|
2081
|
-
method: string;
|
|
2082
|
-
url: string;
|
|
2083
|
-
headers: Pick<Headers, "get">;
|
|
2084
|
-
};
|
|
2085
|
-
type ReadonlyContext = Pick<RouterContextProvider, "get">;
|
|
2086
|
-
type InstrumentableRoute = {
|
|
2087
|
-
id: string;
|
|
2088
|
-
index: boolean | undefined;
|
|
2089
|
-
path: string | undefined;
|
|
2090
|
-
instrument(instrumentations: RouteInstrumentations): void;
|
|
2091
|
-
};
|
|
2092
|
-
type RouteInstrumentations = {
|
|
2093
|
-
lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
2094
|
-
"lazy.loader"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
2095
|
-
"lazy.action"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
2096
|
-
"lazy.middleware"?: InstrumentFunction<RouteLazyInstrumentationInfo>;
|
|
2097
|
-
middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
|
2098
|
-
loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
|
2099
|
-
action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
|
|
2100
|
-
};
|
|
2101
|
-
type RouteLazyInstrumentationInfo = undefined;
|
|
2102
|
-
type RouteHandlerInstrumentationInfo = Readonly<{
|
|
2103
|
-
request: ReadonlyRequest;
|
|
2104
|
-
params: LoaderFunctionArgs["params"];
|
|
2105
|
-
unstable_pattern: string;
|
|
2106
|
-
context: ReadonlyContext;
|
|
2107
|
-
}>;
|
|
2108
|
-
type InstrumentableRouter = {
|
|
2109
|
-
instrument(instrumentations: RouterInstrumentations): void;
|
|
2110
|
-
};
|
|
2111
|
-
type RouterInstrumentations = {
|
|
2112
|
-
navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
|
|
2113
|
-
fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
|
|
2114
|
-
};
|
|
2115
|
-
type RouterNavigationInstrumentationInfo = Readonly<{
|
|
2116
|
-
to: string | number;
|
|
2117
|
-
currentUrl: string;
|
|
2118
|
-
formMethod?: HTMLFormMethod;
|
|
2119
|
-
formEncType?: FormEncType;
|
|
2120
|
-
formData?: FormData;
|
|
2121
|
-
body?: any;
|
|
2122
|
-
}>;
|
|
2123
|
-
type RouterFetchInstrumentationInfo = Readonly<{
|
|
2124
|
-
href: string;
|
|
2125
|
-
currentUrl: string;
|
|
2126
|
-
fetcherKey: string;
|
|
2127
|
-
formMethod?: HTMLFormMethod;
|
|
2128
|
-
formEncType?: FormEncType;
|
|
2129
|
-
formData?: FormData;
|
|
2130
|
-
body?: any;
|
|
2131
|
-
}>;
|
|
2132
|
-
type InstrumentableRequestHandler = {
|
|
2133
|
-
instrument(instrumentations: RequestHandlerInstrumentations): void;
|
|
2134
|
-
};
|
|
2135
|
-
type RequestHandlerInstrumentations = {
|
|
2136
|
-
request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
|
|
2137
|
-
};
|
|
2138
|
-
type RequestHandlerInstrumentationInfo = Readonly<{
|
|
2139
|
-
request: ReadonlyRequest;
|
|
2140
|
-
context: ReadonlyContext;
|
|
2141
|
-
}>;
|
|
2142
|
-
|
|
2143
|
-
/**
|
|
2144
|
-
* A Router instance manages all navigation and data loading/mutations
|
|
2145
|
-
*/
|
|
2146
|
-
interface Router {
|
|
2147
|
-
/**
|
|
2148
|
-
* @private
|
|
2149
|
-
* PRIVATE - DO NOT USE
|
|
2150
|
-
*
|
|
2151
|
-
* Return the basename for the router
|
|
2152
|
-
*/
|
|
2153
|
-
get basename(): RouterInit["basename"];
|
|
2154
|
-
/**
|
|
2155
|
-
* @private
|
|
2156
|
-
* PRIVATE - DO NOT USE
|
|
2157
|
-
*
|
|
2158
|
-
* Return the future config for the router
|
|
2159
|
-
*/
|
|
2160
|
-
get future(): FutureConfig;
|
|
2161
|
-
/**
|
|
2162
|
-
* @private
|
|
2163
|
-
* PRIVATE - DO NOT USE
|
|
2164
|
-
*
|
|
2165
|
-
* Return the current state of the router
|
|
2166
|
-
*/
|
|
2167
|
-
get state(): RouterState;
|
|
2168
|
-
/**
|
|
2169
|
-
* @private
|
|
2170
|
-
* PRIVATE - DO NOT USE
|
|
2171
|
-
*
|
|
2172
|
-
* Return the routes for this router instance
|
|
2173
|
-
*/
|
|
2174
|
-
get routes(): AgnosticDataRouteObject[];
|
|
2566
|
+
}
|
|
2567
|
+
declare const RouteContext: React.Context<RouteContextObject>;
|
|
2568
|
+
|
|
2569
|
+
/**
|
|
2570
|
+
* An object of unknown type for route loaders and actions provided by the
|
|
2571
|
+
* server's `getLoadContext()` function. This is defined as an empty interface
|
|
2572
|
+
* specifically so apps can leverage declaration merging to augment this type
|
|
2573
|
+
* globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
|
|
2574
|
+
*/
|
|
2575
|
+
interface AppLoadContext {
|
|
2576
|
+
[key: string]: unknown;
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
2580
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
2581
|
+
interface HtmlLinkProps {
|
|
2175
2582
|
/**
|
|
2176
|
-
*
|
|
2177
|
-
* PRIVATE - DO NOT USE
|
|
2178
|
-
*
|
|
2179
|
-
* Return the window associated with the router
|
|
2583
|
+
* Address of the hyperlink
|
|
2180
2584
|
*/
|
|
2181
|
-
|
|
2585
|
+
href?: string;
|
|
2182
2586
|
/**
|
|
2183
|
-
*
|
|
2184
|
-
* PRIVATE - DO NOT USE
|
|
2185
|
-
*
|
|
2186
|
-
* Initialize the router, including adding history listeners and kicking off
|
|
2187
|
-
* initial data fetches. Returns a function to cleanup listeners and abort
|
|
2188
|
-
* any in-progress loads
|
|
2587
|
+
* How the element handles crossorigin requests
|
|
2189
2588
|
*/
|
|
2190
|
-
|
|
2589
|
+
crossOrigin?: "anonymous" | "use-credentials";
|
|
2191
2590
|
/**
|
|
2192
|
-
*
|
|
2193
|
-
* PRIVATE - DO NOT USE
|
|
2194
|
-
*
|
|
2195
|
-
* Subscribe to router.state updates
|
|
2196
|
-
*
|
|
2197
|
-
* @param fn function to call with the new state
|
|
2591
|
+
* Relationship between the document containing the hyperlink and the destination resource
|
|
2198
2592
|
*/
|
|
2199
|
-
|
|
2593
|
+
rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
|
|
2200
2594
|
/**
|
|
2201
|
-
*
|
|
2202
|
-
* PRIVATE - DO NOT USE
|
|
2203
|
-
*
|
|
2204
|
-
* Enable scroll restoration behavior in the router
|
|
2205
|
-
*
|
|
2206
|
-
* @param savedScrollPositions Object that will manage positions, in case
|
|
2207
|
-
* it's being restored from sessionStorage
|
|
2208
|
-
* @param getScrollPosition Function to get the active Y scroll position
|
|
2209
|
-
* @param getKey Function to get the key to use for restoration
|
|
2595
|
+
* Applicable media: "screen", "print", "(max-width: 764px)"
|
|
2210
2596
|
*/
|
|
2211
|
-
|
|
2597
|
+
media?: string;
|
|
2212
2598
|
/**
|
|
2213
|
-
*
|
|
2214
|
-
* PRIVATE - DO NOT USE
|
|
2215
|
-
*
|
|
2216
|
-
* Navigate forward/backward in the history stack
|
|
2217
|
-
* @param to Delta to move in the history stack
|
|
2599
|
+
* Integrity metadata used in Subresource Integrity checks
|
|
2218
2600
|
*/
|
|
2219
|
-
|
|
2601
|
+
integrity?: string;
|
|
2220
2602
|
/**
|
|
2221
|
-
*
|
|
2222
|
-
* @param to Path to navigate to
|
|
2223
|
-
* @param opts Navigation options (method, submission, etc.)
|
|
2603
|
+
* Language of the linked resource
|
|
2224
2604
|
*/
|
|
2225
|
-
|
|
2605
|
+
hrefLang?: string;
|
|
2226
2606
|
/**
|
|
2227
|
-
*
|
|
2228
|
-
* PRIVATE - DO NOT USE
|
|
2229
|
-
*
|
|
2230
|
-
* Trigger a fetcher load/submission
|
|
2231
|
-
*
|
|
2232
|
-
* @param key Fetcher key
|
|
2233
|
-
* @param routeId Route that owns the fetcher
|
|
2234
|
-
* @param href href to fetch
|
|
2235
|
-
* @param opts Fetcher options, (method, submission, etc.)
|
|
2607
|
+
* Hint for the type of the referenced resource
|
|
2236
2608
|
*/
|
|
2237
|
-
|
|
2609
|
+
type?: string;
|
|
2238
2610
|
/**
|
|
2239
|
-
*
|
|
2240
|
-
* PRIVATE - DO NOT USE
|
|
2241
|
-
*
|
|
2242
|
-
* Trigger a revalidation of all current route loaders and fetcher loads
|
|
2611
|
+
* Referrer policy for fetches initiated by the element
|
|
2243
2612
|
*/
|
|
2244
|
-
|
|
2613
|
+
referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
|
|
2245
2614
|
/**
|
|
2246
|
-
*
|
|
2247
|
-
* PRIVATE - DO NOT USE
|
|
2248
|
-
*
|
|
2249
|
-
* Utility function to create an href for the given location
|
|
2250
|
-
* @param location
|
|
2615
|
+
* Sizes of the icons (for rel="icon")
|
|
2251
2616
|
*/
|
|
2252
|
-
|
|
2617
|
+
sizes?: string;
|
|
2253
2618
|
/**
|
|
2254
|
-
*
|
|
2255
|
-
* PRIVATE - DO NOT USE
|
|
2256
|
-
*
|
|
2257
|
-
* Utility function to URL encode a destination path according to the internal
|
|
2258
|
-
* history implementation
|
|
2259
|
-
* @param to
|
|
2619
|
+
* Potential destination for a preload request (for rel="preload" and rel="modulepreload")
|
|
2260
2620
|
*/
|
|
2261
|
-
|
|
2621
|
+
as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
|
|
2262
2622
|
/**
|
|
2263
|
-
*
|
|
2264
|
-
* PRIVATE - DO NOT USE
|
|
2265
|
-
*
|
|
2266
|
-
* Get/create a fetcher for the given key
|
|
2267
|
-
* @param key
|
|
2623
|
+
* Color to use when customizing a site's icon (for rel="mask-icon")
|
|
2268
2624
|
*/
|
|
2269
|
-
|
|
2625
|
+
color?: string;
|
|
2270
2626
|
/**
|
|
2271
|
-
*
|
|
2272
|
-
* PRIVATE - DO NOT USE
|
|
2273
|
-
*
|
|
2274
|
-
* Reset the fetcher for a given key
|
|
2275
|
-
* @param key
|
|
2627
|
+
* Whether the link is disabled
|
|
2276
2628
|
*/
|
|
2277
|
-
|
|
2278
|
-
reason?: unknown;
|
|
2279
|
-
}): void;
|
|
2629
|
+
disabled?: boolean;
|
|
2280
2630
|
/**
|
|
2281
|
-
*
|
|
2282
|
-
* PRIVATE - DO NOT USE
|
|
2283
|
-
*
|
|
2284
|
-
* Delete the fetcher for a given key
|
|
2285
|
-
* @param key
|
|
2631
|
+
* The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
|
|
2286
2632
|
*/
|
|
2287
|
-
|
|
2633
|
+
title?: string;
|
|
2288
2634
|
/**
|
|
2289
|
-
*
|
|
2290
|
-
*
|
|
2291
|
-
*
|
|
2292
|
-
* Cleanup listeners and abort any in-progress loads
|
|
2635
|
+
* Images to use in different situations, e.g., high-resolution displays,
|
|
2636
|
+
* small monitors, etc. (for rel="preload")
|
|
2293
2637
|
*/
|
|
2294
|
-
|
|
2638
|
+
imageSrcSet?: string;
|
|
2295
2639
|
/**
|
|
2296
|
-
*
|
|
2297
|
-
* PRIVATE - DO NOT USE
|
|
2298
|
-
*
|
|
2299
|
-
* Get a navigation blocker
|
|
2300
|
-
* @param key The identifier for the blocker
|
|
2301
|
-
* @param fn The blocker function implementation
|
|
2640
|
+
* Image sizes for different page layouts (for rel="preload")
|
|
2302
2641
|
*/
|
|
2303
|
-
|
|
2642
|
+
imageSizes?: string;
|
|
2643
|
+
}
|
|
2644
|
+
interface HtmlLinkPreloadImage extends HtmlLinkProps {
|
|
2304
2645
|
/**
|
|
2305
|
-
*
|
|
2306
|
-
* PRIVATE - DO NOT USE
|
|
2307
|
-
*
|
|
2308
|
-
* Delete a navigation blocker
|
|
2309
|
-
* @param key The identifier for the blocker
|
|
2646
|
+
* Relationship between the document containing the hyperlink and the destination resource
|
|
2310
2647
|
*/
|
|
2311
|
-
|
|
2648
|
+
rel: "preload";
|
|
2312
2649
|
/**
|
|
2313
|
-
*
|
|
2314
|
-
* PRIVATE DO NOT USE
|
|
2315
|
-
*
|
|
2316
|
-
* Patch additional children routes into an existing parent route
|
|
2317
|
-
* @param routeId The parent route id or a callback function accepting `patch`
|
|
2318
|
-
* to perform batch patching
|
|
2319
|
-
* @param children The additional children routes
|
|
2320
|
-
* @param unstable_allowElementMutations Allow mutation or route elements on
|
|
2321
|
-
* existing routes. Intended for RSC-usage
|
|
2322
|
-
* only.
|
|
2650
|
+
* Potential destination for a preload request (for rel="preload" and rel="modulepreload")
|
|
2323
2651
|
*/
|
|
2324
|
-
|
|
2652
|
+
as: "image";
|
|
2325
2653
|
/**
|
|
2326
|
-
*
|
|
2327
|
-
* PRIVATE - DO NOT USE
|
|
2328
|
-
*
|
|
2329
|
-
* HMR needs to pass in-flight route updates to React Router
|
|
2330
|
-
* TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
|
|
2654
|
+
* Address of the hyperlink
|
|
2331
2655
|
*/
|
|
2332
|
-
|
|
2656
|
+
href?: string;
|
|
2333
2657
|
/**
|
|
2334
|
-
*
|
|
2335
|
-
*
|
|
2336
|
-
*
|
|
2337
|
-
* Cause subscribers to re-render. This is used to force a re-render.
|
|
2658
|
+
* Images to use in different situations, e.g., high-resolution displays,
|
|
2659
|
+
* small monitors, etc. (for rel="preload")
|
|
2338
2660
|
*/
|
|
2339
|
-
|
|
2661
|
+
imageSrcSet: string;
|
|
2340
2662
|
/**
|
|
2341
|
-
*
|
|
2342
|
-
* PRIVATE - DO NOT USE
|
|
2343
|
-
*
|
|
2344
|
-
* Internal fetch AbortControllers accessed by unit tests
|
|
2663
|
+
* Image sizes for different page layouts (for rel="preload")
|
|
2345
2664
|
*/
|
|
2346
|
-
|
|
2665
|
+
imageSizes?: string;
|
|
2347
2666
|
}
|
|
2348
2667
|
/**
|
|
2349
|
-
*
|
|
2350
|
-
*
|
|
2668
|
+
* Represents a `<link>` element.
|
|
2669
|
+
*
|
|
2670
|
+
* WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
|
|
2351
2671
|
*/
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
historyAction: Action;
|
|
2357
|
-
/**
|
|
2358
|
-
* The current location reflected by the router
|
|
2359
|
-
*/
|
|
2360
|
-
location: Location;
|
|
2361
|
-
/**
|
|
2362
|
-
* The current set of route matches
|
|
2363
|
-
*/
|
|
2364
|
-
matches: AgnosticDataRouteMatch[];
|
|
2365
|
-
/**
|
|
2366
|
-
* Tracks whether we've completed our initial data load
|
|
2367
|
-
*/
|
|
2368
|
-
initialized: boolean;
|
|
2369
|
-
/**
|
|
2370
|
-
* Current scroll position we should start at for a new view
|
|
2371
|
-
* - number -> scroll position to restore to
|
|
2372
|
-
* - false -> do not restore scroll at all (used during submissions/revalidations)
|
|
2373
|
-
* - null -> don't have a saved position, scroll to hash or top of page
|
|
2374
|
-
*/
|
|
2375
|
-
restoreScrollPosition: number | false | null;
|
|
2376
|
-
/**
|
|
2377
|
-
* Indicate whether this navigation should skip resetting the scroll position
|
|
2378
|
-
* if we are unable to restore the scroll position
|
|
2379
|
-
*/
|
|
2380
|
-
preventScrollReset: boolean;
|
|
2381
|
-
/**
|
|
2382
|
-
* Tracks the state of the current navigation
|
|
2383
|
-
*/
|
|
2384
|
-
navigation: Navigation;
|
|
2385
|
-
/**
|
|
2386
|
-
* Tracks any in-progress revalidations
|
|
2387
|
-
*/
|
|
2388
|
-
revalidation: RevalidationState;
|
|
2389
|
-
/**
|
|
2390
|
-
* Data from the loaders for the current matches
|
|
2391
|
-
*/
|
|
2392
|
-
loaderData: RouteData;
|
|
2393
|
-
/**
|
|
2394
|
-
* Data from the action for the current matches
|
|
2395
|
-
*/
|
|
2396
|
-
actionData: RouteData | null;
|
|
2397
|
-
/**
|
|
2398
|
-
* Errors caught from loaders for the current matches
|
|
2399
|
-
*/
|
|
2400
|
-
errors: RouteData | null;
|
|
2672
|
+
type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
|
|
2673
|
+
imageSizes?: never;
|
|
2674
|
+
});
|
|
2675
|
+
interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
|
|
2401
2676
|
/**
|
|
2402
|
-
*
|
|
2677
|
+
* A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
|
|
2678
|
+
* attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
|
|
2679
|
+
* element
|
|
2403
2680
|
*/
|
|
2404
|
-
|
|
2681
|
+
nonce?: string | undefined;
|
|
2405
2682
|
/**
|
|
2406
|
-
*
|
|
2683
|
+
* The absolute path of the page to prefetch, e.g. `/absolute/path`.
|
|
2407
2684
|
*/
|
|
2408
|
-
|
|
2409
|
-
}
|
|
2410
|
-
/**
|
|
2411
|
-
* Data that can be passed into hydrate a Router from SSR
|
|
2412
|
-
*/
|
|
2413
|
-
type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
|
|
2414
|
-
/**
|
|
2415
|
-
* Future flags to toggle new feature behavior
|
|
2416
|
-
*/
|
|
2417
|
-
interface FutureConfig {
|
|
2418
|
-
}
|
|
2419
|
-
/**
|
|
2420
|
-
* Initialization options for createRouter
|
|
2421
|
-
*/
|
|
2422
|
-
interface RouterInit {
|
|
2423
|
-
routes: AgnosticRouteObject[];
|
|
2424
|
-
history: History;
|
|
2425
|
-
basename?: string;
|
|
2426
|
-
getContext?: () => MaybePromise<RouterContextProvider>;
|
|
2427
|
-
unstable_instrumentations?: unstable_ClientInstrumentation[];
|
|
2428
|
-
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
2429
|
-
future?: Partial<FutureConfig>;
|
|
2430
|
-
hydrationRouteProperties?: string[];
|
|
2431
|
-
hydrationData?: HydrationState;
|
|
2432
|
-
window?: Window;
|
|
2433
|
-
dataStrategy?: DataStrategyFunction;
|
|
2434
|
-
patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
|
|
2435
|
-
}
|
|
2436
|
-
/**
|
|
2437
|
-
* State returned from a server-side query() call
|
|
2438
|
-
*/
|
|
2439
|
-
interface StaticHandlerContext {
|
|
2440
|
-
basename: Router["basename"];
|
|
2441
|
-
location: RouterState["location"];
|
|
2442
|
-
matches: RouterState["matches"];
|
|
2443
|
-
loaderData: RouterState["loaderData"];
|
|
2444
|
-
actionData: RouterState["actionData"];
|
|
2445
|
-
errors: RouterState["errors"];
|
|
2446
|
-
statusCode: number;
|
|
2447
|
-
loaderHeaders: Record<string, Headers>;
|
|
2448
|
-
actionHeaders: Record<string, Headers>;
|
|
2449
|
-
_deepestRenderedBoundaryId?: string | null;
|
|
2685
|
+
page: string;
|
|
2450
2686
|
}
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
}): Promise<any>;
|
|
2687
|
+
type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
|
|
2688
|
+
|
|
2689
|
+
interface RouteModules {
|
|
2690
|
+
[routeId: string]: RouteModule$1 | undefined;
|
|
2691
|
+
}
|
|
2692
|
+
/**
|
|
2693
|
+
* The shape of a route module shipped to the client
|
|
2694
|
+
*/
|
|
2695
|
+
interface RouteModule$1 {
|
|
2696
|
+
clientAction?: ClientActionFunction;
|
|
2697
|
+
clientLoader?: ClientLoaderFunction;
|
|
2698
|
+
clientMiddleware?: MiddlewareFunction<Record<string, DataStrategyResult>>[];
|
|
2699
|
+
ErrorBoundary?: ErrorBoundaryComponent;
|
|
2700
|
+
HydrateFallback?: HydrateFallbackComponent;
|
|
2701
|
+
Layout?: LayoutComponent;
|
|
2702
|
+
default: RouteComponent;
|
|
2703
|
+
handle?: RouteHandle;
|
|
2704
|
+
links?: LinksFunction;
|
|
2705
|
+
meta?: MetaFunction;
|
|
2706
|
+
shouldRevalidate?: ShouldRevalidateFunction;
|
|
2472
2707
|
}
|
|
2473
|
-
type ViewTransitionOpts = {
|
|
2474
|
-
currentLocation: Location;
|
|
2475
|
-
nextLocation: Location;
|
|
2476
|
-
};
|
|
2477
2708
|
/**
|
|
2478
|
-
*
|
|
2709
|
+
* The shape of a route module on the server
|
|
2479
2710
|
*/
|
|
2480
|
-
interface
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2711
|
+
interface ServerRouteModule extends RouteModule$1 {
|
|
2712
|
+
action?: ActionFunction;
|
|
2713
|
+
headers?: HeadersFunction | {
|
|
2714
|
+
[name: string]: string;
|
|
2715
|
+
};
|
|
2716
|
+
loader?: LoaderFunction;
|
|
2717
|
+
middleware?: MiddlewareFunction<Response>[];
|
|
2486
2718
|
}
|
|
2487
2719
|
/**
|
|
2488
|
-
*
|
|
2489
|
-
* for a given location
|
|
2720
|
+
* A function that handles data mutations for a route on the client
|
|
2490
2721
|
*/
|
|
2491
|
-
|
|
2492
|
-
(location: Location, matches: UIMatch[]): string | null;
|
|
2493
|
-
}
|
|
2722
|
+
type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
|
|
2494
2723
|
/**
|
|
2495
|
-
*
|
|
2724
|
+
* Arguments passed to a route `clientAction` function
|
|
2496
2725
|
*/
|
|
2497
|
-
|
|
2498
|
-
()
|
|
2499
|
-
}
|
|
2726
|
+
type ClientActionFunctionArgs = ActionFunctionArgs & {
|
|
2727
|
+
serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
|
|
2728
|
+
};
|
|
2500
2729
|
/**
|
|
2501
|
-
*
|
|
2502
|
-
* of the current route even if it has many. For example, a `route("posts/:id")`
|
|
2503
|
-
* would have both `:id` and `posts` removed from the url.
|
|
2504
|
-
* - "path": relative to the pathname so `..` means remove one segment of the
|
|
2505
|
-
* pathname. For example, a `route("posts/:id")` would have only `:id` removed
|
|
2506
|
-
* from the url.
|
|
2730
|
+
* A function that loads data for a route on the client
|
|
2507
2731
|
*/
|
|
2508
|
-
type
|
|
2509
|
-
|
|
2510
|
-
preventScrollReset?: boolean;
|
|
2511
|
-
relative?: RelativeRoutingType;
|
|
2512
|
-
flushSync?: boolean;
|
|
2732
|
+
type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
|
|
2733
|
+
hydrate?: boolean;
|
|
2513
2734
|
};
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2735
|
+
/**
|
|
2736
|
+
* Arguments passed to a route `clientLoader` function
|
|
2737
|
+
*/
|
|
2738
|
+
type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
|
|
2739
|
+
serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
|
|
2519
2740
|
};
|
|
2520
|
-
type BaseSubmissionOptions = {
|
|
2521
|
-
formMethod?: HTMLFormMethod;
|
|
2522
|
-
formEncType?: FormEncType;
|
|
2523
|
-
} & ({
|
|
2524
|
-
formData: FormData;
|
|
2525
|
-
body?: undefined;
|
|
2526
|
-
} | {
|
|
2527
|
-
formData?: undefined;
|
|
2528
|
-
body: any;
|
|
2529
|
-
});
|
|
2530
2741
|
/**
|
|
2531
|
-
*
|
|
2742
|
+
* ErrorBoundary to display for this route
|
|
2532
2743
|
*/
|
|
2533
|
-
type
|
|
2744
|
+
type ErrorBoundaryComponent = ComponentType;
|
|
2745
|
+
type HeadersArgs = {
|
|
2746
|
+
loaderHeaders: Headers;
|
|
2747
|
+
parentHeaders: Headers;
|
|
2748
|
+
actionHeaders: Headers;
|
|
2749
|
+
errorHeaders: Headers | undefined;
|
|
2750
|
+
};
|
|
2534
2751
|
/**
|
|
2535
|
-
*
|
|
2752
|
+
* A function that returns HTTP headers to be used for a route. These headers
|
|
2753
|
+
* will be merged with (and take precedence over) headers from parent routes.
|
|
2536
2754
|
*/
|
|
2537
|
-
|
|
2755
|
+
interface HeadersFunction {
|
|
2756
|
+
(args: HeadersArgs): Headers | HeadersInit;
|
|
2757
|
+
}
|
|
2538
2758
|
/**
|
|
2539
|
-
*
|
|
2759
|
+
* `<Route HydrateFallback>` component to render on initial loads
|
|
2760
|
+
* when client loaders are present
|
|
2540
2761
|
*/
|
|
2541
|
-
type
|
|
2762
|
+
type HydrateFallbackComponent = ComponentType;
|
|
2542
2763
|
/**
|
|
2543
|
-
*
|
|
2764
|
+
* Optional, root-only `<Route Layout>` component to wrap the root content in.
|
|
2765
|
+
* Useful for defining the <html>/<head>/<body> document shell shared by the
|
|
2766
|
+
* Component, HydrateFallback, and ErrorBoundary
|
|
2544
2767
|
*/
|
|
2545
|
-
type
|
|
2768
|
+
type LayoutComponent = ComponentType<{
|
|
2769
|
+
children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
|
|
2770
|
+
}>;
|
|
2546
2771
|
/**
|
|
2547
|
-
*
|
|
2772
|
+
* A function that defines `<link>` tags to be inserted into the `<head>` of
|
|
2773
|
+
* the document on route transitions.
|
|
2774
|
+
*
|
|
2775
|
+
* @see https://remix.run/route/meta
|
|
2776
|
+
*/
|
|
2777
|
+
interface LinksFunction {
|
|
2778
|
+
(): LinkDescriptor[];
|
|
2779
|
+
}
|
|
2780
|
+
interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
|
|
2781
|
+
id: RouteId;
|
|
2782
|
+
pathname: DataRouteMatch["pathname"];
|
|
2783
|
+
/** @deprecated Use `MetaMatch.loaderData` instead */
|
|
2784
|
+
data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
2785
|
+
loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
2786
|
+
handle?: RouteHandle;
|
|
2787
|
+
params: DataRouteMatch["params"];
|
|
2788
|
+
meta: MetaDescriptor[];
|
|
2789
|
+
error?: unknown;
|
|
2790
|
+
}
|
|
2791
|
+
type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
|
|
2792
|
+
[K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
|
|
2793
|
+
}[keyof MatchLoaders]>;
|
|
2794
|
+
interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
|
2795
|
+
/** @deprecated Use `MetaArgs.loaderData` instead */
|
|
2796
|
+
data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
|
|
2797
|
+
loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
|
|
2798
|
+
params: Params;
|
|
2799
|
+
location: Location;
|
|
2800
|
+
matches: MetaMatches<MatchLoaders>;
|
|
2801
|
+
error?: unknown;
|
|
2802
|
+
}
|
|
2803
|
+
/**
|
|
2804
|
+
* A function that returns an array of data objects to use for rendering
|
|
2805
|
+
* metadata HTML tags in a route. These tags are not rendered on descendant
|
|
2806
|
+
* routes in the route hierarchy. In other words, they will only be rendered on
|
|
2807
|
+
* the route in which they are exported.
|
|
2808
|
+
*
|
|
2809
|
+
* @param Loader - The type of the current route's loader function
|
|
2810
|
+
* @param MatchLoaders - Mapping from a parent route's filepath to its loader
|
|
2811
|
+
* function type
|
|
2812
|
+
*
|
|
2813
|
+
* Note that parent route filepaths are relative to the `app/` directory.
|
|
2814
|
+
*
|
|
2815
|
+
* For example, if this meta function is for `/sales/customers/$customerId`:
|
|
2816
|
+
*
|
|
2817
|
+
* ```ts
|
|
2818
|
+
* // app/root.tsx
|
|
2819
|
+
* const loader = () => ({ hello: "world" })
|
|
2820
|
+
* export type Loader = typeof loader
|
|
2821
|
+
*
|
|
2822
|
+
* // app/routes/sales.tsx
|
|
2823
|
+
* const loader = () => ({ salesCount: 1074 })
|
|
2824
|
+
* export type Loader = typeof loader
|
|
2825
|
+
*
|
|
2826
|
+
* // app/routes/sales/customers.tsx
|
|
2827
|
+
* const loader = () => ({ customerCount: 74 })
|
|
2828
|
+
* export type Loader = typeof loader
|
|
2829
|
+
*
|
|
2830
|
+
* // app/routes/sales/customers/$customersId.tsx
|
|
2831
|
+
* import type { Loader as RootLoader } from "../../../root"
|
|
2832
|
+
* import type { Loader as SalesLoader } from "../../sales"
|
|
2833
|
+
* import type { Loader as CustomersLoader } from "../../sales/customers"
|
|
2834
|
+
*
|
|
2835
|
+
* const loader = () => ({ name: "Customer name" })
|
|
2836
|
+
*
|
|
2837
|
+
* const meta: MetaFunction<typeof loader, {
|
|
2838
|
+
* "root": RootLoader,
|
|
2839
|
+
* "routes/sales": SalesLoader,
|
|
2840
|
+
* "routes/sales/customers": CustomersLoader,
|
|
2841
|
+
* }> = ({ data, matches }) => {
|
|
2842
|
+
* const { name } = data
|
|
2843
|
+
* // ^? string
|
|
2844
|
+
* const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
|
|
2845
|
+
* // ^? number
|
|
2846
|
+
* const { salesCount } = matches.find((match) => match.id === "routes/sales").data
|
|
2847
|
+
* // ^? number
|
|
2848
|
+
* const { hello } = matches.find((match) => match.id === "root").data
|
|
2849
|
+
* // ^? "world"
|
|
2850
|
+
* }
|
|
2851
|
+
* ```
|
|
2548
2852
|
*/
|
|
2549
|
-
|
|
2853
|
+
interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
|
2854
|
+
(args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
|
|
2855
|
+
}
|
|
2856
|
+
type MetaDescriptor = {
|
|
2857
|
+
charSet: "utf-8";
|
|
2858
|
+
} | {
|
|
2859
|
+
title: string;
|
|
2860
|
+
} | {
|
|
2861
|
+
name: string;
|
|
2862
|
+
content: string;
|
|
2863
|
+
} | {
|
|
2864
|
+
property: string;
|
|
2865
|
+
content: string;
|
|
2866
|
+
} | {
|
|
2867
|
+
httpEquiv: string;
|
|
2868
|
+
content: string;
|
|
2869
|
+
} | {
|
|
2870
|
+
"script:ld+json": LdJsonObject;
|
|
2871
|
+
} | {
|
|
2872
|
+
tagName: "meta" | "link";
|
|
2873
|
+
[name: string]: string;
|
|
2874
|
+
} | {
|
|
2875
|
+
[name: string]: unknown;
|
|
2876
|
+
};
|
|
2877
|
+
type LdJsonObject = {
|
|
2878
|
+
[Key in string]: LdJsonValue;
|
|
2879
|
+
} & {
|
|
2880
|
+
[Key in string]?: LdJsonValue | undefined;
|
|
2881
|
+
};
|
|
2882
|
+
type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
|
|
2883
|
+
type LdJsonPrimitive = string | number | boolean | null;
|
|
2884
|
+
type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
2550
2885
|
/**
|
|
2551
|
-
*
|
|
2886
|
+
* A React component that is rendered for a route.
|
|
2552
2887
|
*/
|
|
2553
|
-
type
|
|
2888
|
+
type RouteComponent = ComponentType<{}>;
|
|
2554
2889
|
/**
|
|
2555
|
-
*
|
|
2890
|
+
* An arbitrary object that is associated with a route.
|
|
2891
|
+
*
|
|
2892
|
+
* @see https://remix.run/route/handle
|
|
2556
2893
|
*/
|
|
2557
|
-
type
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2894
|
+
type RouteHandle = unknown;
|
|
2895
|
+
|
|
2896
|
+
type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
|
|
2897
|
+
[key: PropertyKey]: Serializable;
|
|
2898
|
+
} | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
|
|
2899
|
+
|
|
2900
|
+
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
2901
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
2902
|
+
type Func = (...args: any[]) => unknown;
|
|
2903
|
+
type Pretty<T> = {
|
|
2904
|
+
[K in keyof T]: T[K];
|
|
2905
|
+
} & {};
|
|
2906
|
+
type Normalize<T> = _Normalize<UnionKeys<T>, T>;
|
|
2907
|
+
type _Normalize<Key extends keyof any, T> = T extends infer U ? Pretty<{
|
|
2908
|
+
[K in Key as K extends keyof U ? undefined extends U[K] ? never : K : never]: K extends keyof U ? U[K] : never;
|
|
2909
|
+
} & {
|
|
2910
|
+
[K in Key as K extends keyof U ? undefined extends U[K] ? K : never : never]?: K extends keyof U ? U[K] : never;
|
|
2911
|
+
} & {
|
|
2912
|
+
[K in Key as K extends keyof U ? never : K]?: undefined;
|
|
2913
|
+
}> : never;
|
|
2914
|
+
type UnionKeys<T> = T extends any ? keyof T : never;
|
|
2915
|
+
|
|
2916
|
+
type RouteModule = {
|
|
2917
|
+
meta?: Func;
|
|
2918
|
+
links?: Func;
|
|
2919
|
+
headers?: Func;
|
|
2920
|
+
loader?: Func;
|
|
2921
|
+
clientLoader?: Func;
|
|
2922
|
+
action?: Func;
|
|
2923
|
+
clientAction?: Func;
|
|
2924
|
+
HydrateFallback?: Func;
|
|
2925
|
+
default?: Func;
|
|
2926
|
+
ErrorBoundary?: Func;
|
|
2927
|
+
[key: string]: unknown;
|
|
2588
2928
|
};
|
|
2589
|
-
|
|
2590
|
-
type RevalidationState = "idle" | "loading";
|
|
2929
|
+
|
|
2591
2930
|
/**
|
|
2592
|
-
*
|
|
2931
|
+
* A brand that can be applied to a type to indicate that it will serialize
|
|
2932
|
+
* to a specific type when transported to the client from a loader.
|
|
2933
|
+
* Only use this if you have additional serialization/deserialization logic
|
|
2934
|
+
* in your application.
|
|
2593
2935
|
*/
|
|
2594
|
-
type
|
|
2936
|
+
type unstable_SerializesTo<T> = {
|
|
2937
|
+
unstable__ReactRouter_SerializesTo: [T];
|
|
2938
|
+
};
|
|
2939
|
+
|
|
2940
|
+
type 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 ReadonlyMap<infer K, infer V> ? ReadonlyMap<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<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> ? {
|
|
2941
|
+
[K in keyof T]: Serialize<T[K]>;
|
|
2942
|
+
} : undefined;
|
|
2943
|
+
type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
|
|
2944
|
+
type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
|
|
2945
|
+
type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
|
|
2946
|
+
type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
|
|
2947
|
+
type ServerDataFrom<T> = ServerData<DataFrom<T>>;
|
|
2948
|
+
type ClientDataFrom<T> = ClientData<DataFrom<T>>;
|
|
2949
|
+
type ClientDataFunctionArgs<Params> = {
|
|
2950
|
+
/**
|
|
2951
|
+
* 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.
|
|
2952
|
+
*
|
|
2953
|
+
* @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.
|
|
2954
|
+
**/
|
|
2955
|
+
request: Request;
|
|
2595
2956
|
/**
|
|
2596
|
-
*
|
|
2957
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
2958
|
+
* @example
|
|
2959
|
+
* // app/routes.ts
|
|
2960
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
2597
2961
|
*
|
|
2598
|
-
*
|
|
2599
|
-
*
|
|
2600
|
-
*
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
text: undefined;
|
|
2608
|
-
formData: undefined;
|
|
2609
|
-
json: undefined;
|
|
2610
|
-
/**
|
|
2611
|
-
* If the fetcher has never been called, this will be undefined.
|
|
2612
|
-
*/
|
|
2613
|
-
data: TData | undefined;
|
|
2614
|
-
};
|
|
2962
|
+
* // app/team.tsx
|
|
2963
|
+
* export function clientLoader({
|
|
2964
|
+
* params,
|
|
2965
|
+
* }: Route.ClientLoaderArgs) {
|
|
2966
|
+
* params.teamId;
|
|
2967
|
+
* // ^ string
|
|
2968
|
+
* }
|
|
2969
|
+
**/
|
|
2970
|
+
params: Params;
|
|
2615
2971
|
/**
|
|
2616
|
-
*
|
|
2617
|
-
* call to {@link FetcherWithComponents.load | `fetcher.load`}.
|
|
2618
|
-
*
|
|
2619
|
-
* ```tsx
|
|
2620
|
-
* // somewhere
|
|
2621
|
-
* <button onClick={() => fetcher.load("/some/route") }>Load</button>
|
|
2972
|
+
* When `future.v8_middleware` is not enabled, this is undefined.
|
|
2622
2973
|
*
|
|
2623
|
-
*
|
|
2624
|
-
*
|
|
2625
|
-
*
|
|
2974
|
+
* When `future.v8_middleware` is enabled, this is an instance of
|
|
2975
|
+
* `RouterContextProvider` and can be used to access context values
|
|
2976
|
+
* from your route middlewares. You may pass in initial context values in your
|
|
2977
|
+
* `<HydratedRouter getContext>` prop
|
|
2626
2978
|
*/
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
text: Submission["text"] | undefined;
|
|
2633
|
-
formData: Submission["formData"] | undefined;
|
|
2634
|
-
json: Submission["json"] | undefined;
|
|
2635
|
-
data: TData | undefined;
|
|
2636
|
-
};
|
|
2979
|
+
context: Readonly<RouterContextProvider>;
|
|
2980
|
+
};
|
|
2981
|
+
type ServerDataFunctionArgs<Params> = {
|
|
2982
|
+
/** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the url, method, headers (such as cookies), and request body from the request. */
|
|
2983
|
+
request: Request;
|
|
2637
2984
|
/**
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2985
|
+
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
|
|
2986
|
+
* @example
|
|
2987
|
+
* // app/routes.ts
|
|
2988
|
+
* route("teams/:teamId", "./team.tsx"),
|
|
2989
|
+
*
|
|
2990
|
+
* // app/team.tsx
|
|
2991
|
+
* export function loader({
|
|
2992
|
+
* params,
|
|
2993
|
+
* }: Route.LoaderArgs) {
|
|
2994
|
+
* params.teamId;
|
|
2995
|
+
* // ^ string
|
|
2996
|
+
* }
|
|
2997
|
+
**/
|
|
2998
|
+
params: Params;
|
|
2999
|
+
/**
|
|
3000
|
+
* Without `future.v8_middleware` enabled, this is the context passed in
|
|
3001
|
+
* to your server adapter's `getLoadContext` function. It's a way to bridge the
|
|
3002
|
+
* gap between the adapter's request/response API with your React Router app.
|
|
3003
|
+
* It is only applicable if you are using a custom server adapter.
|
|
3004
|
+
*
|
|
3005
|
+
* With `future.v8_middleware` enabled, this is an instance of
|
|
3006
|
+
* `RouterContextProvider` and can be used for type-safe access to
|
|
3007
|
+
* context value set in your route middlewares. If you are using a custom
|
|
3008
|
+
* server adapter, you may provide an initial set of context values from your
|
|
3009
|
+
* `getLoadContext` function.
|
|
2654
3010
|
*/
|
|
2655
|
-
|
|
2656
|
-
state: "submitting";
|
|
2657
|
-
formMethod: Submission["formMethod"];
|
|
2658
|
-
formAction: Submission["formAction"];
|
|
2659
|
-
formEncType: Submission["formEncType"];
|
|
2660
|
-
text: Submission["text"];
|
|
2661
|
-
formData: Submission["formData"];
|
|
2662
|
-
json: Submission["json"];
|
|
2663
|
-
data: TData | undefined;
|
|
2664
|
-
};
|
|
3011
|
+
context: MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : AppLoadContext;
|
|
2665
3012
|
};
|
|
2666
|
-
type
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
type
|
|
2686
|
-
type
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
}) => boolean;
|
|
2691
|
-
declare const IDLE_NAVIGATION: NavigationStates["Idle"];
|
|
2692
|
-
declare const IDLE_FETCHER: FetcherStates["Idle"];
|
|
2693
|
-
declare const IDLE_BLOCKER: BlockerUnblocked;
|
|
2694
|
-
/**
|
|
2695
|
-
* Create a router and listen to history POP navigations
|
|
2696
|
-
*/
|
|
2697
|
-
declare function createRouter(init: RouterInit): Router;
|
|
2698
|
-
interface CreateStaticHandlerOptions {
|
|
2699
|
-
basename?: string;
|
|
2700
|
-
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
2701
|
-
unstable_instrumentations?: Pick<unstable_ServerInstrumentation, "route">[];
|
|
2702
|
-
future?: {};
|
|
2703
|
-
}
|
|
3013
|
+
type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
|
|
3014
|
+
ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
|
|
3015
|
+
] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
|
|
3016
|
+
type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
|
|
3017
|
+
type IsHydrate<ClientLoader> = ClientLoader extends {
|
|
3018
|
+
hydrate: true;
|
|
3019
|
+
} ? true : ClientLoader extends {
|
|
3020
|
+
hydrate: false;
|
|
3021
|
+
} ? false : false;
|
|
3022
|
+
type GetLoaderData<T extends RouteModule> = _DataLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
|
|
3023
|
+
HydrateFallback: Func;
|
|
3024
|
+
} ? true : false>;
|
|
3025
|
+
type _DataLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [
|
|
3026
|
+
HasHydrateFallback,
|
|
3027
|
+
ClientLoaderHydrate
|
|
3028
|
+
] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [
|
|
3029
|
+
IsDefined<ClientLoaderData>,
|
|
3030
|
+
IsDefined<ServerLoaderData>
|
|
3031
|
+
] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderData : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
|
|
3032
|
+
type GetActionData<T extends RouteModule> = _DataActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
|
|
3033
|
+
type _DataActionData<ServerActionData, ClientActionData> = Awaited<[
|
|
3034
|
+
IsDefined<ServerActionData>,
|
|
3035
|
+
IsDefined<ClientActionData>
|
|
3036
|
+
] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
|
|
2704
3037
|
|
|
2705
|
-
export { type
|
|
3038
|
+
export { type Equal as $, type ActionFunction as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyResult as D, type Navigation as E, type Func as F, type GetLoaderData as G, type HeadersFunction as H, Action as I, type RouteObject as J, type InitialEntry as K, type Location as L, type MetaFunction as M, type Normalize as N, type HydrationState as O, type Params as P, type IndexRouteObject as Q, type RouteModule as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type RouteComponentType as V, type HydrateFallbackType as W, type ErrorBoundaryType as X, type NonIndexRouteObject as Y, type AppLoadContext as Z, type MiddlewareEnabled as _, type ClientLoaderFunction as a, Route as a$, type RouterState as a0, type PatchRoutesOnNavigationFunction as a1, type DataRouteObject as a2, type StaticHandler as a3, type GetScrollPositionFunction as a4, type GetScrollRestorationKeyFunction as a5, type StaticHandlerContext as a6, type Fetcher as a7, type NavigationStates as a8, type RouterSubscriber as a9, isRouteErrorResponse as aA, matchPath as aB, matchRoutes as aC, redirect as aD, redirectDocument as aE, replace as aF, resolvePath as aG, type DataRouteMatch as aH, type Navigator as aI, type PatchRoutesOnNavigationFunctionArgs as aJ, type RouteMatch as aK, AwaitContextProvider as aL, type AwaitProps as aM, type IndexRouteProps as aN, type LayoutRouteProps as aO, type MemoryRouterOpts as aP, type MemoryRouterProps as aQ, type NavigateProps as aR, type OutletProps as aS, type PathRouteProps as aT, type RouteProps as aU, type RouterProps as aV, type RoutesProps as aW, Await as aX, MemoryRouter as aY, Navigate as aZ, Outlet as a_, type RouterNavigateOptions as aa, type RouterFetchOptions as ab, type RevalidationState as ac, type ActionFunctionArgs as ad, type DataStrategyFunctionArgs as ae, type DataStrategyMatch as af, DataWithResponseInit as ag, type ErrorResponse as ah, type FormEncType as ai, type FormMethod as aj, type HTMLFormMethod as ak, type LazyRouteFunction as al, type LoaderFunctionArgs as am, type MiddlewareFunction as an, type PathParam as ao, type RedirectFunction as ap, type RouterContext as aq, type ShouldRevalidateFunctionArgs as ar, createContext as as, createPath as at, parsePath as au, IDLE_NAVIGATION as av, IDLE_FETCHER as aw, IDLE_BLOCKER as ax, data as ay, generatePath as az, type LinksFunction as b, Router as b0, RouterProvider as b1, Routes as b2, createMemoryRouter as b3, createRoutesFromChildren as b4, createRoutesFromElements as b5, renderMatches as b6, type ClientActionFunctionArgs as b7, type ClientLoaderFunctionArgs as b8, type HeadersArgs as b9, type History as bA, type FutureConfig as bB, type CreateStaticHandlerOptions as bC, type MetaArgs as ba, type PageLinkDescriptor as bb, type HtmlLinkDescriptor as bc, type Future as bd, type unstable_SerializesTo as be, createBrowserHistory as bf, invariant as bg, createRouter as bh, ErrorResponseImpl as bi, DataRouterContext as bj, DataRouterStateContext as bk, FetchersContext as bl, LocationContext as bm, NavigationContext as bn, RouteContext as bo, ViewTransitionContext as bp, hydrationRouteProperties as bq, mapRouteProperties as br, WithComponentProps as bs, withComponentProps as bt, WithHydrateFallbackProps as bu, withHydrateFallbackProps as bv, WithErrorBoundaryProps as bw, withErrorBoundaryProps as bx, type RouteManifest as by, type ServerRouteModule as bz, RouterContextProvider as c, type LoaderFunction as d, type RouterInit as e, type RouterProviderProps as f, type LinkDescriptor as g, type Pretty as h, type MetaDescriptor as i, type ServerDataFunctionArgs as j, type MiddlewareNextFunction as k, type ClientDataFunctionArgs as l, type ServerDataFrom as m, type GetActionData as n, type Router$1 as o, type RouteModules as p, type DataStrategyFunction as q, type NavigateOptions as r, type Blocker as s, type SerializeFrom as t, type unstable_ClientOnErrorFunction as u, type RelativeRoutingType as v, type ParamParseKey as w, type Path as x, type PathPattern as y, type PathMatch as z };
|