react-router 0.0.0-experimental-a65d6f5 → 0.0.0-experimental-c19b79d

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.
Files changed (65) hide show
  1. package/dist/development/{chunk-ZLVXSGFL.js → chunk-2G2U5HGB.js} +161 -164
  2. package/dist/development/{chunk-CWSJ6RYI.mjs → chunk-AGOH44BE.mjs} +51 -67
  3. package/dist/development/{chunk-47MIYFLC.mjs → chunk-IMKEG5CI.mjs} +29 -309
  4. package/dist/development/{chunk-QOFB7XZ5.js → chunk-LUB73E44.js} +70 -347
  5. package/dist/development/{router-DQIRhYoj.d.mts → context-BqL5Eckq.d.mts} +1288 -1441
  6. package/dist/development/dom-export.d.mts +4 -59
  7. package/dist/development/dom-export.d.ts +3 -59
  8. package/dist/development/dom-export.js +5 -8
  9. package/dist/development/dom-export.mjs +5 -8
  10. package/dist/{production/index-react-server-client-lf74v6ET.d.mts → development/index-react-server-client-2EDmGlsZ.d.mts} +77 -140
  11. package/dist/development/{index-react-server-client-lf74v6ET.d.mts → index-react-server-client-DKvU8YRr.d.ts} +134 -198
  12. package/dist/development/index-react-server-client.d.mts +3 -3
  13. package/dist/development/index-react-server-client.d.ts +2 -3
  14. package/dist/development/index-react-server-client.js +4 -4
  15. package/dist/development/index-react-server-client.mjs +2 -2
  16. package/dist/development/index-react-server.d.mts +1 -106
  17. package/dist/development/index-react-server.d.ts +1 -106
  18. package/dist/development/index-react-server.js +8 -181
  19. package/dist/development/index-react-server.mjs +8 -181
  20. package/dist/development/index.d.mts +20 -13
  21. package/dist/development/index.d.ts +18 -13
  22. package/dist/development/index.js +147 -161
  23. package/dist/development/index.mjs +5 -3
  24. package/dist/development/lib/types/internal.d.mts +3 -3
  25. package/dist/development/lib/types/internal.d.ts +2 -3
  26. package/dist/development/lib/types/internal.js +1 -1
  27. package/dist/development/lib/types/internal.mjs +1 -1
  28. package/dist/development/{register-DiOIlEq5.d.mts → register-BrVEYTED.d.mts} +7 -1
  29. package/dist/{production/register-DiOIlEq5.d.mts → development/register-D8NQoPsO.d.ts} +7 -1
  30. package/dist/development/{routeModules--SgCTStn.d.mts → route-data-CDwqkzPE.d.mts} +147 -157
  31. package/dist/{production/routeModules-rxNxBmdR.d.ts → development/routeModules-BmVo7q9e.d.ts} +1046 -73
  32. package/dist/production/{chunk-ZOHTOBOT.js → chunk-2L5AG5Y5.js} +70 -347
  33. package/dist/production/{chunk-UAAA7FTX.mjs → chunk-AODJW4D3.mjs} +51 -67
  34. package/dist/production/{chunk-4SPSFXAZ.js → chunk-FGRCWJDI.js} +161 -164
  35. package/dist/production/{chunk-MMAHTIVZ.mjs → chunk-UOQCOPF6.mjs} +29 -309
  36. package/dist/production/{router-DQIRhYoj.d.mts → context-BqL5Eckq.d.mts} +1288 -1441
  37. package/dist/production/dom-export.d.mts +4 -59
  38. package/dist/production/dom-export.d.ts +3 -59
  39. package/dist/production/dom-export.js +5 -8
  40. package/dist/production/dom-export.mjs +5 -8
  41. package/dist/{development/index-react-server-client-Iw2PMej2.d.ts → production/index-react-server-client-2EDmGlsZ.d.mts} +77 -140
  42. package/dist/production/{index-react-server-client-Iw2PMej2.d.ts → index-react-server-client-DKvU8YRr.d.ts} +134 -198
  43. package/dist/production/index-react-server-client.d.mts +3 -3
  44. package/dist/production/index-react-server-client.d.ts +2 -3
  45. package/dist/production/index-react-server-client.js +4 -4
  46. package/dist/production/index-react-server-client.mjs +2 -2
  47. package/dist/production/index-react-server.d.mts +1 -106
  48. package/dist/production/index-react-server.d.ts +1 -106
  49. package/dist/production/index-react-server.js +8 -181
  50. package/dist/production/index-react-server.mjs +8 -181
  51. package/dist/production/index.d.mts +20 -13
  52. package/dist/production/index.d.ts +18 -13
  53. package/dist/production/index.js +147 -161
  54. package/dist/production/index.mjs +5 -3
  55. package/dist/production/lib/types/internal.d.mts +3 -3
  56. package/dist/production/lib/types/internal.d.ts +2 -3
  57. package/dist/production/lib/types/internal.js +1 -1
  58. package/dist/production/lib/types/internal.mjs +1 -1
  59. package/dist/{development/register-DiOIlEq5.d.ts → production/register-BrVEYTED.d.mts} +7 -1
  60. package/dist/production/{register-DiOIlEq5.d.ts → register-D8NQoPsO.d.ts} +7 -1
  61. package/dist/production/{routeModules--SgCTStn.d.mts → route-data-CDwqkzPE.d.mts} +147 -157
  62. package/dist/{development/routeModules-rxNxBmdR.d.ts → production/routeModules-BmVo7q9e.d.ts} +1046 -73
  63. package/package.json +1 -1
  64. package/dist/development/instrumentation-BWRz1MRU.d.ts +0 -1138
  65. package/dist/production/instrumentation-BWRz1MRU.d.ts +0 -1138
@@ -394,11 +394,6 @@ type DefaultContext = MiddlewareEnabled extends true ? Readonly<RouterContextPro
394
394
  interface DataFunctionArgs<Context> {
395
395
  /** 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
396
  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
397
  /**
403
398
  * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
404
399
  * @example
@@ -619,7 +614,7 @@ type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = Agn
619
614
  * properties from framework-agnostic properties
620
615
  */
621
616
  interface MapRoutePropertiesFunction {
622
- (route: AgnosticDataRouteObject): {
617
+ (route: AgnosticRouteObject): {
623
618
  hasErrorBoundary: boolean;
624
619
  } & Record<string, any>;
625
620
  }
@@ -1044,1678 +1039,1530 @@ declare class ErrorResponseImpl implements ErrorResponse {
1044
1039
  */
1045
1040
  declare function isRouteErrorResponse(error: any): error is ErrorResponse;
1046
1041
 
1047
- declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
1048
- hasErrorBoundary: boolean;
1049
- };
1050
- declare const hydrationRouteProperties: (keyof RouteObject)[];
1051
1042
  /**
1052
- * @category Data Routers
1043
+ * A Router instance manages all navigation and data loading/mutations
1053
1044
  */
1054
- interface MemoryRouterOpts {
1045
+ interface Router$1 {
1055
1046
  /**
1056
- * Basename path for the application.
1047
+ * @private
1048
+ * PRIVATE - DO NOT USE
1049
+ *
1050
+ * Return the basename for the router
1057
1051
  */
1058
- basename?: string;
1052
+ get basename(): RouterInit["basename"];
1059
1053
  /**
1060
- * A function that returns an {@link RouterContextProvider} instance
1061
- * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
1062
- * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
1063
- * This function is called to generate a fresh `context` instance on each
1064
- * navigation or fetcher call.
1054
+ * @private
1055
+ * PRIVATE - DO NOT USE
1056
+ *
1057
+ * Return the future config for the router
1065
1058
  */
1066
- getContext?: RouterInit["getContext"];
1059
+ get future(): FutureConfig;
1067
1060
  /**
1068
- * Future flags to enable for the router.
1061
+ * @private
1062
+ * PRIVATE - DO NOT USE
1063
+ *
1064
+ * Return the current state of the router
1069
1065
  */
1070
- future?: Partial<FutureConfig>;
1066
+ get state(): RouterState;
1071
1067
  /**
1072
- * Hydration data to initialize the router with if you have already performed
1073
- * data loading on the server.
1068
+ * @private
1069
+ * PRIVATE - DO NOT USE
1070
+ *
1071
+ * Return the routes for this router instance
1074
1072
  */
1075
- hydrationData?: HydrationState;
1073
+ get routes(): AgnosticDataRouteObject[];
1076
1074
  /**
1077
- * Initial entries in the in-memory history stack
1075
+ * @private
1076
+ * PRIVATE - DO NOT USE
1077
+ *
1078
+ * Return the window associated with the router
1078
1079
  */
1079
- initialEntries?: InitialEntry[];
1080
+ get window(): RouterInit["window"];
1080
1081
  /**
1081
- * Index of `initialEntries` the application should initialize to
1082
+ * @private
1083
+ * PRIVATE - DO NOT USE
1084
+ *
1085
+ * Initialize the router, including adding history listeners and kicking off
1086
+ * initial data fetches. Returns a function to cleanup listeners and abort
1087
+ * any in-progress loads
1082
1088
  */
1083
- initialIndex?: number;
1089
+ initialize(): Router$1;
1084
1090
  /**
1085
- * Array of instrumentation objects allowing you to instrument the router and
1086
- * individual routes prior to router initialization (and on any subsequently
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.
1091
+ * @private
1092
+ * PRIVATE - DO NOT USE
1091
1093
  *
1092
- * ```tsx
1093
- * let router = createBrowserRouter(routes, {
1094
- * unstable_instrumentations: [logging]
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
- * ```
1094
+ * Subscribe to router.state updates
1095
+ *
1096
+ * @param fn function to call with the new state
1134
1097
  */
1135
- unstable_instrumentations?: unstable_ClientInstrumentation[];
1098
+ subscribe(fn: RouterSubscriber): () => void;
1136
1099
  /**
1137
- * Override the default data strategy of loading in parallel.
1138
- * Only intended for advanced usage.
1100
+ * @private
1101
+ * PRIVATE - DO NOT USE
1102
+ *
1103
+ * Enable scroll restoration behavior in the router
1104
+ *
1105
+ * @param savedScrollPositions Object that will manage positions, in case
1106
+ * it's being restored from sessionStorage
1107
+ * @param getScrollPosition Function to get the active Y scroll position
1108
+ * @param getKey Function to get the key to use for restoration
1139
1109
  */
1140
- dataStrategy?: DataStrategyFunction;
1110
+ enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
1141
1111
  /**
1142
- * Lazily define portions of the route tree on navigations.
1112
+ * @private
1113
+ * PRIVATE - DO NOT USE
1114
+ *
1115
+ * Navigate forward/backward in the history stack
1116
+ * @param to Delta to move in the history stack
1143
1117
  */
1144
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
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 {
1118
+ navigate(to: number): Promise<void>;
1179
1119
  /**
1180
- * The {@link DataRouter} instance to use for navigation and data fetching.
1120
+ * Navigate to the given path
1121
+ * @param to Path to navigate to
1122
+ * @param opts Navigation options (method, submission, etc.)
1181
1123
  */
1182
- router: Router;
1124
+ navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
1183
1125
  /**
1184
- * The [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
1185
- * implementation to use for flushing updates.
1126
+ * @private
1127
+ * PRIVATE - DO NOT USE
1186
1128
  *
1187
- * You usually don't have to worry about this:
1188
- * - The `RouterProvider` exported from `react-router/dom` handles this internally for you
1189
- * - If you are rendering in a non-DOM environment, you can import
1190
- * `RouterProvider` from `react-router` and ignore this prop
1129
+ * Trigger a fetcher load/submission
1130
+ *
1131
+ * @param key Fetcher key
1132
+ * @param routeId Route that owns the fetcher
1133
+ * @param href href to fetch
1134
+ * @param opts Fetcher options, (method, submission, etc.)
1191
1135
  */
1192
- flushSync?: (fn: () => unknown) => undefined;
1136
+ fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
1193
1137
  /**
1194
- * An error handler function that will be called for any loader/action/render
1195
- * errors that are encountered in your application. This is useful for
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.
1138
+ * @private
1139
+ * PRIVATE - DO NOT USE
1202
1140
  *
1203
- * ```tsx
1204
- * <RouterProvider unstable_onError=(error, errorInfo) => {
1205
- * console.error(error, errorInfo);
1206
- * reportToErrorService(error, errorInfo);
1207
- * }} />
1208
- * ```
1141
+ * Trigger a revalidation of all current route loaders and fetcher loads
1209
1142
  */
1210
- unstable_onError?: unstable_ClientOnErrorFunction;
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 {
1143
+ revalidate(): Promise<void>;
1248
1144
  /**
1249
- * Application basename
1145
+ * @private
1146
+ * PRIVATE - DO NOT USE
1147
+ *
1148
+ * Utility function to create an href for the given location
1149
+ * @param location
1250
1150
  */
1251
- basename?: string;
1151
+ createHref(location: Location | URL): string;
1252
1152
  /**
1253
- * Nested {@link Route} elements describing the route tree
1153
+ * @private
1154
+ * PRIVATE - DO NOT USE
1155
+ *
1156
+ * Utility function to URL encode a destination path according to the internal
1157
+ * history implementation
1158
+ * @param to
1254
1159
  */
1255
- children?: React.ReactNode;
1160
+ encodeLocation(to: To): Path;
1256
1161
  /**
1257
- * Initial entries in the in-memory history stack
1162
+ * @private
1163
+ * PRIVATE - DO NOT USE
1164
+ *
1165
+ * Get/create a fetcher for the given key
1166
+ * @param key
1258
1167
  */
1259
- initialEntries?: InitialEntry[];
1168
+ getFetcher<TData = any>(key: string): Fetcher<TData>;
1260
1169
  /**
1261
- * Index of `initialEntries` the application should initialize to
1170
+ * @internal
1171
+ * PRIVATE - DO NOT USE
1172
+ *
1173
+ * Reset the fetcher for a given key
1174
+ * @param key
1262
1175
  */
1263
- initialIndex?: number;
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 {
1176
+ resetFetcher(key: string, opts?: {
1177
+ reason?: unknown;
1178
+ }): void;
1284
1179
  /**
1285
- * The path to navigate to. This can be a string or a {@link Path} object
1286
- */
1287
- to: To;
1288
- /**
1289
- * Whether to replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1290
- * stack
1180
+ * @private
1181
+ * PRIVATE - DO NOT USE
1182
+ *
1183
+ * Delete the fetcher for a given key
1184
+ * @param key
1291
1185
  */
1292
- replace?: boolean;
1186
+ deleteFetcher(key: string): void;
1293
1187
  /**
1294
- * State to pass to the new {@link Location} to store in [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state).
1188
+ * @private
1189
+ * PRIVATE - DO NOT USE
1190
+ *
1191
+ * Cleanup listeners and abort any in-progress loads
1295
1192
  */
1296
- state?: any;
1193
+ dispose(): void;
1297
1194
  /**
1298
- * How to interpret relative routing in the `to` prop.
1299
- * See {@link RelativeRoutingType}.
1195
+ * @private
1196
+ * PRIVATE - DO NOT USE
1197
+ *
1198
+ * Get a navigation blocker
1199
+ * @param key The identifier for the blocker
1200
+ * @param fn The blocker function implementation
1300
1201
  */
1301
- relative?: RelativeRoutingType;
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 {
1202
+ getBlocker(key: string, fn: BlockerFunction): Blocker;
1328
1203
  /**
1329
- * Provides a context value to the element tree below the outlet. Use when
1330
- * the parent route needs to provide values to child routes.
1331
- *
1332
- * ```tsx
1333
- * <Outlet context={myContextValue} />
1334
- * ```
1204
+ * @private
1205
+ * PRIVATE - DO NOT USE
1335
1206
  *
1336
- * Access the context with {@link useOutletContext}.
1207
+ * Delete a navigation blocker
1208
+ * @param key The identifier for the blocker
1337
1209
  */
1338
- context?: unknown;
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 {
1210
+ deleteBlocker(key: string): void;
1367
1211
  /**
1368
- * Whether the path should be case-sensitive. Defaults to `false`.
1212
+ * @private
1213
+ * PRIVATE DO NOT USE
1214
+ *
1215
+ * Patch additional children routes into an existing parent route
1216
+ * @param routeId The parent route id or a callback function accepting `patch`
1217
+ * to perform batch patching
1218
+ * @param children The additional children routes
1219
+ * @param unstable_allowElementMutations Allow mutation or route elements on
1220
+ * existing routes. Intended for RSC-usage
1221
+ * only.
1369
1222
  */
1370
- caseSensitive?: NonIndexRouteObject["caseSensitive"];
1223
+ patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
1371
1224
  /**
1372
- * The path pattern to match. If unspecified or empty, then this becomes a
1373
- * layout route.
1225
+ * @private
1226
+ * PRIVATE - DO NOT USE
1227
+ *
1228
+ * HMR needs to pass in-flight route updates to React Router
1229
+ * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
1374
1230
  */
1375
- path?: NonIndexRouteObject["path"];
1231
+ _internalSetRoutes(routes: AgnosticRouteObject[]): void;
1376
1232
  /**
1377
- * The unique identifier for this route (for use with {@link DataRouter}s)
1233
+ * @private
1234
+ * PRIVATE - DO NOT USE
1235
+ *
1236
+ * Cause subscribers to re-render. This is used to force a re-render.
1378
1237
  */
1379
- id?: NonIndexRouteObject["id"];
1238
+ _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
1380
1239
  /**
1381
- * A function that returns a promise that resolves to the route object.
1382
- * Used for code-splitting routes.
1383
- * See [`lazy`](../../start/data/route-object#lazy).
1240
+ * @private
1241
+ * PRIVATE - DO NOT USE
1242
+ *
1243
+ * Internal fetch AbortControllers accessed by unit tests
1384
1244
  */
1385
- lazy?: LazyRouteFunction<NonIndexRouteObject>;
1245
+ _internalFetchControllers: Map<string, AbortController>;
1246
+ }
1247
+ /**
1248
+ * State maintained internally by the router. During a navigation, all states
1249
+ * reflect the "old" location unless otherwise noted.
1250
+ */
1251
+ interface RouterState {
1386
1252
  /**
1387
- * The route middleware.
1388
- * See [`middleware`](../../start/data/route-object#middleware).
1253
+ * The action of the most recent navigation
1389
1254
  */
1390
- middleware?: NonIndexRouteObject["middleware"];
1255
+ historyAction: Action;
1391
1256
  /**
1392
- * The route loader.
1393
- * See [`loader`](../../start/data/route-object#loader).
1257
+ * The current location reflected by the router
1394
1258
  */
1395
- loader?: NonIndexRouteObject["loader"];
1259
+ location: Location;
1396
1260
  /**
1397
- * The route action.
1398
- * See [`action`](../../start/data/route-object#action).
1261
+ * The current set of route matches
1399
1262
  */
1400
- action?: NonIndexRouteObject["action"];
1401
- hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
1263
+ matches: AgnosticDataRouteMatch[];
1402
1264
  /**
1403
- * The route shouldRevalidate function.
1404
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
1265
+ * Tracks whether we've completed our initial data load
1405
1266
  */
1406
- shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
1267
+ initialized: boolean;
1407
1268
  /**
1408
- * The route handle.
1269
+ * Current scroll position we should start at for a new view
1270
+ * - number -> scroll position to restore to
1271
+ * - false -> do not restore scroll at all (used during submissions/revalidations)
1272
+ * - null -> don't have a saved position, scroll to hash or top of page
1409
1273
  */
1410
- handle?: NonIndexRouteObject["handle"];
1274
+ restoreScrollPosition: number | false | null;
1411
1275
  /**
1412
- * Whether this is an index route.
1276
+ * Indicate whether this navigation should skip resetting the scroll position
1277
+ * if we are unable to restore the scroll position
1413
1278
  */
1414
- index?: false;
1279
+ preventScrollReset: boolean;
1415
1280
  /**
1416
- * Child Route components
1281
+ * Tracks the state of the current navigation
1417
1282
  */
1418
- children?: React.ReactNode;
1283
+ navigation: Navigation;
1419
1284
  /**
1420
- * The React element to render when this Route matches.
1421
- * Mutually exclusive with `Component`.
1285
+ * Tracks any in-progress revalidations
1422
1286
  */
1423
- element?: React.ReactNode | null;
1287
+ revalidation: RevalidationState;
1424
1288
  /**
1425
- * The React element to render while this router is loading data.
1426
- * Mutually exclusive with `HydrateFallback`.
1289
+ * Data from the loaders for the current matches
1427
1290
  */
1428
- hydrateFallbackElement?: React.ReactNode | null;
1291
+ loaderData: RouteData;
1429
1292
  /**
1430
- * The React element to render at this route if an error occurs.
1431
- * Mutually exclusive with `ErrorBoundary`.
1293
+ * Data from the action for the current matches
1432
1294
  */
1433
- errorElement?: React.ReactNode | null;
1295
+ actionData: RouteData | null;
1434
1296
  /**
1435
- * The React Component to render when this route matches.
1436
- * Mutually exclusive with `element`.
1297
+ * Errors caught from loaders for the current matches
1437
1298
  */
1438
- Component?: React.ComponentType | null;
1299
+ errors: RouteData | null;
1439
1300
  /**
1440
- * The React Component to render while this router is loading data.
1441
- * Mutually exclusive with `hydrateFallbackElement`.
1301
+ * Map of current fetchers
1442
1302
  */
1443
- HydrateFallback?: React.ComponentType | null;
1303
+ fetchers: Map<string, Fetcher>;
1444
1304
  /**
1445
- * The React Component to render at this route if an error occurs.
1446
- * Mutually exclusive with `errorElement`.
1305
+ * Map of current blockers
1447
1306
  */
1448
- ErrorBoundary?: React.ComponentType | null;
1307
+ blockers: Map<string, Blocker>;
1449
1308
  }
1450
1309
  /**
1451
- * @category Types
1310
+ * Data that can be passed into hydrate a Router from SSR
1452
1311
  */
1453
- interface LayoutRouteProps extends PathRouteProps {
1312
+ type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
1313
+ /**
1314
+ * Future flags to toggle new feature behavior
1315
+ */
1316
+ interface FutureConfig {
1454
1317
  }
1455
1318
  /**
1456
- * @category Types
1319
+ * Initialization options for createRouter
1457
1320
  */
1458
- interface IndexRouteProps {
1459
- /**
1460
- * Whether the path should be case-sensitive. Defaults to `false`.
1461
- */
1462
- caseSensitive?: IndexRouteObject["caseSensitive"];
1463
- /**
1464
- * The path pattern to match. If unspecified or empty, then this becomes a
1465
- * layout route.
1466
- */
1467
- path?: IndexRouteObject["path"];
1468
- /**
1469
- * The unique identifier for this route (for use with {@link DataRouter}s)
1470
- */
1471
- id?: IndexRouteObject["id"];
1472
- /**
1473
- * A function that returns a promise that resolves to the route object.
1474
- * Used for code-splitting routes.
1475
- * See [`lazy`](../../start/data/route-object#lazy).
1476
- */
1477
- lazy?: LazyRouteFunction<IndexRouteObject>;
1478
- /**
1479
- * The route middleware.
1480
- * See [`middleware`](../../start/data/route-object#middleware).
1481
- */
1482
- middleware?: IndexRouteObject["middleware"];
1483
- /**
1484
- * The route loader.
1485
- * See [`loader`](../../start/data/route-object#loader).
1486
- */
1487
- loader?: IndexRouteObject["loader"];
1488
- /**
1489
- * The route action.
1490
- * See [`action`](../../start/data/route-object#action).
1491
- */
1492
- action?: IndexRouteObject["action"];
1493
- hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
1494
- /**
1495
- * The route shouldRevalidate function.
1496
- * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
1497
- */
1498
- shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
1499
- /**
1500
- * The route handle.
1501
- */
1502
- handle?: IndexRouteObject["handle"];
1503
- /**
1504
- * Whether this is an index route.
1505
- */
1506
- index: true;
1507
- /**
1508
- * Child Route components
1509
- */
1510
- children?: undefined;
1511
- /**
1512
- * The React element to render when this Route matches.
1513
- * Mutually exclusive with `Component`.
1514
- */
1515
- element?: React.ReactNode | null;
1516
- /**
1517
- * The React element to render while this router is loading data.
1518
- * Mutually exclusive with `HydrateFallback`.
1519
- */
1520
- hydrateFallbackElement?: React.ReactNode | null;
1521
- /**
1522
- * The React element to render at this route if an error occurs.
1523
- * Mutually exclusive with `ErrorBoundary`.
1524
- */
1525
- errorElement?: React.ReactNode | null;
1526
- /**
1527
- * The React Component to render when this route matches.
1528
- * Mutually exclusive with `element`.
1529
- */
1530
- Component?: React.ComponentType | null;
1531
- /**
1532
- * The React Component to render while this router is loading data.
1533
- * Mutually exclusive with `hydrateFallbackElement`.
1534
- */
1535
- HydrateFallback?: React.ComponentType | null;
1536
- /**
1537
- * The React Component to render at this route if an error occurs.
1538
- * Mutually exclusive with `errorElement`.
1539
- */
1540
- ErrorBoundary?: React.ComponentType | null;
1321
+ interface RouterInit {
1322
+ routes: AgnosticRouteObject[];
1323
+ history: History;
1324
+ basename?: string;
1325
+ getContext?: () => MaybePromise<RouterContextProvider>;
1326
+ mapRouteProperties?: MapRoutePropertiesFunction;
1327
+ future?: Partial<FutureConfig>;
1328
+ hydrationRouteProperties?: string[];
1329
+ hydrationData?: HydrationState;
1330
+ window?: Window;
1331
+ dataStrategy?: DataStrategyFunction;
1332
+ patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
1541
1333
  }
1542
- type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
1543
1334
  /**
1544
- * Configures an element to render when a pattern matches the current location.
1545
- * It must be rendered within a {@link Routes} element. Note that these routes
1546
- * do not participate in data loading, actions, code splitting, or any other
1547
- * route module features.
1548
- *
1549
- * @example
1550
- * // Usually used in a declarative router
1551
- * function App() {
1552
- * return (
1553
- * <BrowserRouter>
1554
- * <Routes>
1555
- * <Route index element={<StepOne />} />
1556
- * <Route path="step-2" element={<StepTwo />} />
1557
- * <Route path="step-3" element={<StepThree />} />
1558
- * </Routes>
1559
- * </BrowserRouter>
1560
- * );
1561
- * }
1562
- *
1563
- * // But can be used with a data router as well if you prefer the JSX notation
1564
- * const routes = createRoutesFromElements(
1565
- * <>
1566
- * <Route index loader={step1Loader} Component={StepOne} />
1567
- * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
1568
- * <Route path="step-3" loader={step3Loader} Component={StepThree} />
1569
- * </>
1570
- * );
1571
- *
1572
- * const router = createBrowserRouter(routes);
1573
- *
1574
- * function App() {
1575
- * return <RouterProvider router={router} />;
1576
- * }
1577
- *
1578
- * @public
1579
- * @category Components
1580
- * @param props Props
1581
- * @param {PathRouteProps.action} props.action n/a
1582
- * @param {PathRouteProps.caseSensitive} props.caseSensitive n/a
1583
- * @param {PathRouteProps.Component} props.Component n/a
1584
- * @param {PathRouteProps.children} props.children n/a
1585
- * @param {PathRouteProps.element} props.element n/a
1586
- * @param {PathRouteProps.ErrorBoundary} props.ErrorBoundary n/a
1587
- * @param {PathRouteProps.errorElement} props.errorElement n/a
1588
- * @param {PathRouteProps.handle} props.handle n/a
1589
- * @param {PathRouteProps.HydrateFallback} props.HydrateFallback n/a
1590
- * @param {PathRouteProps.hydrateFallbackElement} props.hydrateFallbackElement n/a
1591
- * @param {PathRouteProps.id} props.id n/a
1592
- * @param {PathRouteProps.index} props.index n/a
1593
- * @param {PathRouteProps.lazy} props.lazy n/a
1594
- * @param {PathRouteProps.loader} props.loader n/a
1595
- * @param {PathRouteProps.path} props.path n/a
1596
- * @param {PathRouteProps.shouldRevalidate} props.shouldRevalidate n/a
1597
- * @returns {void}
1335
+ * State returned from a server-side query() call
1598
1336
  */
1599
- declare function Route(props: RouteProps): React.ReactElement | null;
1337
+ interface StaticHandlerContext {
1338
+ basename: Router$1["basename"];
1339
+ location: RouterState["location"];
1340
+ matches: RouterState["matches"];
1341
+ loaderData: RouterState["loaderData"];
1342
+ actionData: RouterState["actionData"];
1343
+ errors: RouterState["errors"];
1344
+ statusCode: number;
1345
+ loaderHeaders: Record<string, Headers>;
1346
+ actionHeaders: Record<string, Headers>;
1347
+ _deepestRenderedBoundaryId?: string | null;
1348
+ }
1600
1349
  /**
1601
- * @category Types
1350
+ * A StaticHandler instance manages a singular SSR navigation/fetch event
1602
1351
  */
1603
- interface RouterProps {
1604
- /**
1605
- * The base path for the application. This is prepended to all locations
1606
- */
1607
- basename?: string;
1608
- /**
1609
- * Nested {@link Route} elements describing the route tree
1610
- */
1611
- children?: React.ReactNode;
1612
- /**
1613
- * The location to match against. Defaults to the current location.
1614
- * This can be a string or a {@link Location} object.
1615
- */
1616
- location: Partial<Location> | string;
1617
- /**
1618
- * The type of navigation that triggered this `location` change.
1619
- * Defaults to {@link NavigationType.Pop}.
1620
- */
1621
- navigationType?: Action;
1622
- /**
1623
- * The navigator to use for navigation. This is usually a history object
1624
- * or a custom navigator that implements the {@link Navigator} interface.
1625
- */
1626
- navigator: Navigator;
1627
- /**
1628
- * Whether this router is static or not (used for SSR). If `true`, the router
1629
- * will not be reactive to location changes.
1630
- */
1631
- static?: boolean;
1352
+ interface StaticHandler {
1353
+ dataRoutes: AgnosticDataRouteObject[];
1354
+ query(request: Request, opts?: {
1355
+ requestContext?: unknown;
1356
+ filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
1357
+ skipLoaderErrorBubbling?: boolean;
1358
+ skipRevalidation?: boolean;
1359
+ dataStrategy?: DataStrategyFunction<unknown>;
1360
+ generateMiddlewareResponse?: (query: (r: Request, args?: {
1361
+ filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
1362
+ }) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
1363
+ }): Promise<StaticHandlerContext | Response>;
1364
+ queryRoute(request: Request, opts?: {
1365
+ routeId?: string;
1366
+ requestContext?: unknown;
1367
+ dataStrategy?: DataStrategyFunction<unknown>;
1368
+ generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
1369
+ }): Promise<any>;
1632
1370
  }
1371
+ type ViewTransitionOpts = {
1372
+ currentLocation: Location;
1373
+ nextLocation: Location;
1374
+ };
1633
1375
  /**
1634
- * Provides location context for the rest of the app.
1635
- *
1636
- * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
1637
- * router that is more specific to your environment such as a {@link BrowserRouter}
1638
- * in web browsers or a {@link ServerRouter} for server rendering.
1639
- *
1640
- * @public
1641
- * @category Declarative Routers
1642
- * @mode declarative
1643
- * @param props Props
1644
- * @param {RouterProps.basename} props.basename n/a
1645
- * @param {RouterProps.children} props.children n/a
1646
- * @param {RouterProps.location} props.location n/a
1647
- * @param {RouterProps.navigationType} props.navigationType n/a
1648
- * @param {RouterProps.navigator} props.navigator n/a
1649
- * @param {RouterProps.static} props.static n/a
1650
- * @returns React element for the rendered router or `null` if the location does
1651
- * not match the {@link props.basename}
1376
+ * Subscriber function signature for changes to router state
1652
1377
  */
1653
- declare function Router$1({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, }: RouterProps): React.ReactElement | null;
1378
+ interface RouterSubscriber {
1379
+ (state: RouterState, opts: {
1380
+ deletedFetchers: string[];
1381
+ viewTransitionOpts?: ViewTransitionOpts;
1382
+ flushSync: boolean;
1383
+ }): void;
1384
+ }
1654
1385
  /**
1655
- * @category Types
1386
+ * Function signature for determining the key to be used in scroll restoration
1387
+ * for a given location
1656
1388
  */
1657
- interface RoutesProps {
1658
- /**
1659
- * Nested {@link Route} elements
1660
- */
1661
- children?: React.ReactNode;
1662
- /**
1663
- * The {@link Location} to match against. Defaults to the current location.
1664
- */
1665
- location?: Partial<Location> | string;
1389
+ interface GetScrollRestorationKeyFunction {
1390
+ (location: Location, matches: UIMatch[]): string | null;
1666
1391
  }
1667
1392
  /**
1668
- * Renders a branch of {@link Route | `<Route>`s} that best matches the current
1669
- * location. Note that these routes do not participate in [data loading](../../start/framework/route-module#loader),
1670
- * [`action`](../../start/framework/route-module#action), code splitting, or
1671
- * any other [route module](../../start/framework/route-module) features.
1672
- *
1673
- * @example
1674
- * import { Route, Routes } from "react-router";
1675
- *
1676
- * <Routes>
1677
- * <Route index element={<StepOne />} />
1678
- * <Route path="step-2" element={<StepTwo />} />
1679
- * <Route path="step-3" element={<StepThree />}>
1680
- * </Routes>
1681
- *
1682
- * @public
1683
- * @category Components
1684
- * @param props Props
1685
- * @param {RoutesProps.children} props.children n/a
1686
- * @param {RoutesProps.location} props.location n/a
1687
- * @returns React element for the rendered routes or `null` if no route matches
1393
+ * Function signature for determining the current scroll position
1688
1394
  */
1689
- declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
1690
- interface AwaitResolveRenderFunction<Resolve = any> {
1691
- (data: Awaited<Resolve>): React.ReactNode;
1395
+ interface GetScrollPositionFunction {
1396
+ (): number;
1692
1397
  }
1693
1398
  /**
1694
- * @category Types
1399
+ * - "route": relative to the route hierarchy so `..` means remove all segments
1400
+ * of the current route even if it has many. For example, a `route("posts/:id")`
1401
+ * would have both `:id` and `posts` removed from the url.
1402
+ * - "path": relative to the pathname so `..` means remove one segment of the
1403
+ * pathname. For example, a `route("posts/:id")` would have only `:id` removed
1404
+ * from the url.
1695
1405
  */
1696
- interface AwaitProps<Resolve> {
1697
- /**
1698
- * When using a function, the resolved value is provided as the parameter.
1699
- *
1700
- * ```tsx [2]
1701
- * <Await resolve={reviewsPromise}>
1702
- * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
1703
- * </Await>
1704
- * ```
1705
- *
1706
- * When using React elements, {@link useAsyncValue} will provide the
1707
- * resolved value:
1708
- *
1709
- * ```tsx [2]
1710
- * <Await resolve={reviewsPromise}>
1711
- * <Reviews />
1712
- * </Await>
1713
- *
1714
- * function Reviews() {
1715
- * const resolvedReviews = useAsyncValue();
1716
- * return <div>...</div>;
1717
- * }
1718
- * ```
1719
- */
1720
- children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
1406
+ type RelativeRoutingType = "route" | "path";
1407
+ type BaseNavigateOrFetchOptions = {
1408
+ preventScrollReset?: boolean;
1409
+ relative?: RelativeRoutingType;
1410
+ flushSync?: boolean;
1411
+ };
1412
+ type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
1413
+ replace?: boolean;
1414
+ state?: any;
1415
+ fromRouteId?: string;
1416
+ viewTransition?: boolean;
1417
+ };
1418
+ type BaseSubmissionOptions = {
1419
+ formMethod?: HTMLFormMethod;
1420
+ formEncType?: FormEncType;
1421
+ } & ({
1422
+ formData: FormData;
1423
+ body?: undefined;
1424
+ } | {
1425
+ formData?: undefined;
1426
+ body: any;
1427
+ });
1428
+ /**
1429
+ * Options for a navigate() call for a normal (non-submission) navigation
1430
+ */
1431
+ type LinkNavigateOptions = BaseNavigateOptions;
1432
+ /**
1433
+ * Options for a navigate() call for a submission navigation
1434
+ */
1435
+ type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
1436
+ /**
1437
+ * Options to pass to navigate() for a navigation
1438
+ */
1439
+ type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
1440
+ /**
1441
+ * Options for a fetch() load
1442
+ */
1443
+ type LoadFetchOptions = BaseNavigateOrFetchOptions;
1444
+ /**
1445
+ * Options for a fetch() submission
1446
+ */
1447
+ type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
1448
+ /**
1449
+ * Options to pass to fetch()
1450
+ */
1451
+ type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
1452
+ /**
1453
+ * Potential states for state.navigation
1454
+ */
1455
+ type NavigationStates = {
1456
+ Idle: {
1457
+ state: "idle";
1458
+ location: undefined;
1459
+ formMethod: undefined;
1460
+ formAction: undefined;
1461
+ formEncType: undefined;
1462
+ formData: undefined;
1463
+ json: undefined;
1464
+ text: undefined;
1465
+ };
1466
+ Loading: {
1467
+ state: "loading";
1468
+ location: Location;
1469
+ formMethod: Submission["formMethod"] | undefined;
1470
+ formAction: Submission["formAction"] | undefined;
1471
+ formEncType: Submission["formEncType"] | undefined;
1472
+ formData: Submission["formData"] | undefined;
1473
+ json: Submission["json"] | undefined;
1474
+ text: Submission["text"] | undefined;
1475
+ };
1476
+ Submitting: {
1477
+ state: "submitting";
1478
+ location: Location;
1479
+ formMethod: Submission["formMethod"];
1480
+ formAction: Submission["formAction"];
1481
+ formEncType: Submission["formEncType"];
1482
+ formData: Submission["formData"];
1483
+ json: Submission["json"];
1484
+ text: Submission["text"];
1485
+ };
1486
+ };
1487
+ type Navigation = NavigationStates[keyof NavigationStates];
1488
+ type RevalidationState = "idle" | "loading";
1489
+ /**
1490
+ * Potential states for fetchers
1491
+ */
1492
+ type FetcherStates<TData = any> = {
1721
1493
  /**
1722
- * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1723
- * rejects.
1724
- *
1725
- * ```tsx
1726
- * <Await
1727
- * errorElement={<div>Oops</div>}
1728
- * resolve={reviewsPromise}
1729
- * >
1730
- * <Reviews />
1731
- * </Await>
1732
- * ```
1733
- *
1734
- * To provide a more contextual error, you can use the {@link useAsyncError} in a
1735
- * child component
1494
+ * The fetcher is not calling a loader or action
1736
1495
  *
1737
1496
  * ```tsx
1738
- * <Await
1739
- * errorElement={<ReviewsError />}
1740
- * resolve={reviewsPromise}
1741
- * >
1742
- * <Reviews />
1743
- * </Await>
1744
- *
1745
- * function ReviewsError() {
1746
- * const error = useAsyncError();
1747
- * return <div>Error loading reviews: {error.message}</div>;
1748
- * }
1497
+ * fetcher.state === "idle"
1749
1498
  * ```
1750
- *
1751
- * If you do not provide an `errorElement`, the rejected value will bubble up
1752
- * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
1753
- * and be accessible via the {@link useRouteError} hook.
1754
1499
  */
1755
- errorElement?: React.ReactNode;
1500
+ Idle: {
1501
+ state: "idle";
1502
+ formMethod: undefined;
1503
+ formAction: undefined;
1504
+ formEncType: undefined;
1505
+ text: undefined;
1506
+ formData: undefined;
1507
+ json: undefined;
1508
+ /**
1509
+ * If the fetcher has never been called, this will be undefined.
1510
+ */
1511
+ data: TData | undefined;
1512
+ };
1756
1513
  /**
1757
- * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
1758
- * returned from a [`loader`](../../start/framework/route-module#loader) to be
1759
- * resolved and rendered.
1514
+ * The fetcher is loading data from a {@link LoaderFunction | loader} from a
1515
+ * call to {@link FetcherWithComponents.load | `fetcher.load`}.
1760
1516
  *
1761
1517
  * ```tsx
1762
- * import { Await, useLoaderData } from "react-router";
1763
- *
1764
- * export async function loader() {
1765
- * let reviews = getReviews(); // not awaited
1766
- * let book = await getBook();
1767
- * return {
1768
- * book,
1769
- * reviews, // this is a promise
1770
- * };
1771
- * }
1772
- *
1773
- * export default function Book() {
1774
- * const {
1775
- * book,
1776
- * reviews, // this is the same promise
1777
- * } = useLoaderData();
1518
+ * // somewhere
1519
+ * <button onClick={() => fetcher.load("/some/route") }>Load</button>
1778
1520
  *
1779
- * return (
1780
- * <div>
1781
- * <h1>{book.title}</h1>
1782
- * <p>{book.description}</p>
1783
- * <React.Suspense fallback={<ReviewsSkeleton />}>
1784
- * <Await
1785
- * // and is the promise we pass to Await
1786
- * resolve={reviews}
1787
- * >
1788
- * <Reviews />
1789
- * </Await>
1790
- * </React.Suspense>
1791
- * </div>
1792
- * );
1793
- * }
1521
+ * // the state will update
1522
+ * fetcher.state === "loading"
1794
1523
  * ```
1795
1524
  */
1796
- resolve: Resolve;
1525
+ Loading: {
1526
+ state: "loading";
1527
+ formMethod: Submission["formMethod"] | undefined;
1528
+ formAction: Submission["formAction"] | undefined;
1529
+ formEncType: Submission["formEncType"] | undefined;
1530
+ text: Submission["text"] | undefined;
1531
+ formData: Submission["formData"] | undefined;
1532
+ json: Submission["json"] | undefined;
1533
+ data: TData | undefined;
1534
+ };
1535
+ /**
1536
+ 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`}.
1537
+
1538
+ ```tsx
1539
+ // somewhere
1540
+ <input
1541
+ onChange={e => {
1542
+ fetcher.submit(event.currentTarget.form, { method: "post" });
1543
+ }}
1544
+ />
1545
+
1546
+ // the state will update
1547
+ fetcher.state === "submitting"
1548
+
1549
+ // and formData will be available
1550
+ fetcher.formData
1551
+ ```
1552
+ */
1553
+ Submitting: {
1554
+ state: "submitting";
1555
+ formMethod: Submission["formMethod"];
1556
+ formAction: Submission["formAction"];
1557
+ formEncType: Submission["formEncType"];
1558
+ text: Submission["text"];
1559
+ formData: Submission["formData"];
1560
+ json: Submission["json"];
1561
+ data: TData | undefined;
1562
+ };
1563
+ };
1564
+ type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
1565
+ interface BlockerBlocked {
1566
+ state: "blocked";
1567
+ reset: () => void;
1568
+ proceed: () => void;
1569
+ location: Location;
1570
+ }
1571
+ interface BlockerUnblocked {
1572
+ state: "unblocked";
1573
+ reset: undefined;
1574
+ proceed: undefined;
1575
+ location: undefined;
1576
+ }
1577
+ interface BlockerProceeding {
1578
+ state: "proceeding";
1579
+ reset: undefined;
1580
+ proceed: undefined;
1581
+ location: Location;
1797
1582
  }
1583
+ type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1584
+ type BlockerFunction = (args: {
1585
+ currentLocation: Location;
1586
+ nextLocation: Location;
1587
+ historyAction: Action;
1588
+ }) => boolean;
1589
+ declare const IDLE_NAVIGATION: NavigationStates["Idle"];
1590
+ declare const IDLE_FETCHER: FetcherStates["Idle"];
1591
+ declare const IDLE_BLOCKER: BlockerUnblocked;
1798
1592
  /**
1799
- * Used to render promise values with automatic error handling.
1800
- *
1801
- * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
1802
- *
1803
- * @example
1804
- * import { Await, useLoaderData } from "react-router";
1805
- *
1806
- * export async function loader() {
1807
- * // not awaited
1808
- * const reviews = getReviews();
1809
- * // awaited (blocks the transition)
1810
- * const book = await fetch("/api/book").then((res) => res.json());
1811
- * return { book, reviews };
1812
- * }
1813
- *
1814
- * function Book() {
1815
- * const { book, reviews } = useLoaderData();
1816
- * return (
1817
- * <div>
1818
- * <h1>{book.title}</h1>
1819
- * <p>{book.description}</p>
1820
- * <React.Suspense fallback={<ReviewsSkeleton />}>
1821
- * <Await
1822
- * resolve={reviews}
1823
- * errorElement={
1824
- * <div>Could not load reviews 😬</div>
1825
- * }
1826
- * children={(resolvedReviews) => (
1827
- * <Reviews items={resolvedReviews} />
1828
- * )}
1829
- * />
1830
- * </React.Suspense>
1831
- * </div>
1832
- * );
1833
- * }
1593
+ * Create a router and listen to history POP navigations
1594
+ */
1595
+ declare function createRouter(init: RouterInit): Router$1;
1596
+ interface CreateStaticHandlerOptions {
1597
+ basename?: string;
1598
+ mapRouteProperties?: MapRoutePropertiesFunction;
1599
+ future?: {};
1600
+ }
1601
+
1602
+ declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
1603
+ hasErrorBoundary: boolean;
1604
+ };
1605
+ declare const hydrationRouteProperties: (keyof RouteObject)[];
1606
+ /**
1607
+ * @category Data Routers
1608
+ */
1609
+ interface MemoryRouterOpts {
1610
+ /**
1611
+ * Basename path for the application.
1612
+ */
1613
+ basename?: string;
1614
+ /**
1615
+ * A function that returns an {@link RouterContextProvider} instance
1616
+ * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
1617
+ * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
1618
+ * This function is called to generate a fresh `context` instance on each
1619
+ * navigation or fetcher call.
1620
+ */
1621
+ getContext?: RouterInit["getContext"];
1622
+ /**
1623
+ * Future flags to enable for the router.
1624
+ */
1625
+ future?: Partial<FutureConfig>;
1626
+ /**
1627
+ * Hydration data to initialize the router with if you have already performed
1628
+ * data loading on the server.
1629
+ */
1630
+ hydrationData?: HydrationState;
1631
+ /**
1632
+ * Initial entries in the in-memory history stack
1633
+ */
1634
+ initialEntries?: InitialEntry[];
1635
+ /**
1636
+ * Index of `initialEntries` the application should initialize to
1637
+ */
1638
+ initialIndex?: number;
1639
+ /**
1640
+ * Override the default data strategy of loading in parallel.
1641
+ * Only intended for advanced usage.
1642
+ */
1643
+ dataStrategy?: DataStrategyFunction;
1644
+ /**
1645
+ * Lazily define portions of the route tree on navigations.
1646
+ */
1647
+ patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
1648
+ }
1649
+ /**
1650
+ * Create a new {@link DataRouter} that manages the application path using an
1651
+ * in-memory [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1652
+ * stack. Useful for non-browser environments without a DOM API.
1834
1653
  *
1835
1654
  * @public
1836
- * @category Components
1837
- * @mode framework
1655
+ * @category Data Routers
1838
1656
  * @mode data
1839
- * @param props Props
1840
- * @param {AwaitProps.children} props.children n/a
1841
- * @param {AwaitProps.errorElement} props.errorElement n/a
1842
- * @param {AwaitProps.resolve} props.resolve n/a
1843
- * @returns React element for the rendered awaited value
1657
+ * @param routes Application routes
1658
+ * @param opts Options
1659
+ * @param {MemoryRouterOpts.basename} opts.basename n/a
1660
+ * @param {MemoryRouterOpts.dataStrategy} opts.dataStrategy n/a
1661
+ * @param {MemoryRouterOpts.future} opts.future n/a
1662
+ * @param {MemoryRouterOpts.getContext} opts.getContext n/a
1663
+ * @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
1664
+ * @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
1665
+ * @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
1666
+ * @param {MemoryRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
1667
+ * @returns An initialized {@link DataRouter} to pass to {@link RouterProvider | `<RouterProvider>`}
1844
1668
  */
1845
- declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
1669
+ declare function createMemoryRouter(routes: RouteObject[], opts?: MemoryRouterOpts): Router$1;
1846
1670
  /**
1847
- * Creates a route config from a React "children" object, which is usually
1848
- * either a `<Route>` element or an array of them. Used internally by
1849
- * `<Routes>` to create a route config from its children.
1850
- *
1851
- * @category Utils
1852
- * @mode data
1853
- * @param children The React children to convert into a route config
1854
- * @param parentPath The path of the parent route, used to generate unique IDs.
1855
- * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
1671
+ * Function signature for client side error handling for loader/actions errors
1672
+ * and rendering errors via `componentDidCatch`
1856
1673
  */
1857
- declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
1674
+ interface unstable_ClientOnErrorFunction {
1675
+ (error: unknown, errorInfo?: React.ErrorInfo): void;
1676
+ }
1858
1677
  /**
1859
- * Create route objects from JSX elements instead of arrays of objects.
1678
+ * @category Types
1679
+ */
1680
+ interface RouterProviderProps {
1681
+ /**
1682
+ * The {@link DataRouter} instance to use for navigation and data fetching.
1683
+ */
1684
+ router: Router$1;
1685
+ /**
1686
+ * The [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
1687
+ * implementation to use for flushing updates.
1688
+ *
1689
+ * You usually don't have to worry about this:
1690
+ * - The `RouterProvider` exported from `react-router/dom` handles this internally for you
1691
+ * - If you are rendering in a non-DOM environment, you can import
1692
+ * `RouterProvider` from `react-router` and ignore this prop
1693
+ */
1694
+ flushSync?: (fn: () => unknown) => undefined;
1695
+ /**
1696
+ * An error handler function that will be called for any loader/action/render
1697
+ * errors that are encountered in your application. This is useful for
1698
+ * logging or reporting errors instead of the `ErrorBoundary` because it's not
1699
+ * subject to re-rendering and will only run one time per error.
1700
+ *
1701
+ * The `errorInfo` parameter is passed along from
1702
+ * [`componentDidCatch`](https://react.dev/reference/react/Component#componentdidcatch)
1703
+ * and is only present for render errors.
1704
+ *
1705
+ * ```tsx
1706
+ * <RouterProvider unstable_onError=(error, errorInfo) => {
1707
+ * console.error(error, errorInfo);
1708
+ * reportToErrorService(error, errorInfo);
1709
+ * }} />
1710
+ * ```
1711
+ */
1712
+ unstable_onError?: unstable_ClientOnErrorFunction;
1713
+ }
1714
+ /**
1715
+ * Render the UI for the given {@link DataRouter}. This component should
1716
+ * typically be at the top of an app's element tree.
1860
1717
  *
1861
- * @example
1862
- * const routes = createRoutesFromElements(
1863
- * <>
1864
- * <Route index loader={step1Loader} Component={StepOne} />
1865
- * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
1866
- * <Route path="step-3" loader={step3Loader} Component={StepThree} />
1867
- * </>
1868
- * );
1718
+ * ```tsx
1719
+ * import { createBrowserRouter } from "react-router";
1720
+ * import { RouterProvider } from "react-router/dom";
1721
+ * import { createRoot } from "react-dom/client";
1869
1722
  *
1870
1723
  * const router = createBrowserRouter(routes);
1724
+ * createRoot(document.getElementById("root")).render(
1725
+ * <RouterProvider router={router} />
1726
+ * );
1727
+ * ```
1728
+ *
1729
+ * <docs-info>Please note that this component is exported both from
1730
+ * `react-router` and `react-router/dom` with the only difference being that the
1731
+ * latter automatically wires up `react-dom`'s [`flushSync`](https://react.dev/reference/react-dom/flushSync)
1732
+ * implementation. You _almost always_ want to use the version from
1733
+ * `react-router/dom` unless you're running in a non-DOM environment.</docs-info>
1871
1734
  *
1872
- * function App() {
1873
- * return <RouterProvider router={router} />;
1874
- * }
1875
1735
  *
1876
- * @name createRoutesFromElements
1877
1736
  * @public
1878
- * @category Utils
1737
+ * @category Data Routers
1879
1738
  * @mode data
1880
- * @param children The React children to convert into a route config
1881
- * @param parentPath The path of the parent route, used to generate unique IDs.
1882
- * This is used for internal recursion and is not intended to be used by the
1883
- * application developer.
1884
- * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
1739
+ * @param props Props
1740
+ * @param {RouterProviderProps.flushSync} props.flushSync n/a
1741
+ * @param {RouterProviderProps.unstable_onError} props.unstable_onError n/a
1742
+ * @param {RouterProviderProps.router} props.router n/a
1743
+ * @returns React element for the rendered router
1885
1744
  */
1886
- declare const createRoutesFromElements: typeof createRoutesFromChildren;
1745
+ declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, unstable_onError, }: RouterProviderProps): React.ReactElement;
1887
1746
  /**
1888
- * Renders the result of {@link matchRoutes} into a React element.
1747
+ * @category Types
1748
+ */
1749
+ interface MemoryRouterProps {
1750
+ /**
1751
+ * Application basename
1752
+ */
1753
+ basename?: string;
1754
+ /**
1755
+ * Nested {@link Route} elements describing the route tree
1756
+ */
1757
+ children?: React.ReactNode;
1758
+ /**
1759
+ * Initial entries in the in-memory history stack
1760
+ */
1761
+ initialEntries?: InitialEntry[];
1762
+ /**
1763
+ * Index of `initialEntries` the application should initialize to
1764
+ */
1765
+ initialIndex?: number;
1766
+ }
1767
+ /**
1768
+ * A declarative {@link Router | `<Router>`} that stores all entries in memory.
1889
1769
  *
1890
1770
  * @public
1891
- * @category Utils
1892
- * @param matches The array of {@link RouteMatch | route matches} to render
1893
- * @returns A React element that renders the matched routes or `null` if no matches
1771
+ * @category Declarative Routers
1772
+ * @mode declarative
1773
+ * @param props Props
1774
+ * @param {MemoryRouterProps.basename} props.basename n/a
1775
+ * @param {MemoryRouterProps.children} props.children n/a
1776
+ * @param {MemoryRouterProps.initialEntries} props.initialEntries n/a
1777
+ * @param {MemoryRouterProps.initialIndex} props.initialIndex n/a
1778
+ * @returns A declarative in-memory {@link Router | `<Router>`} for client-side
1779
+ * routing.
1894
1780
  */
1895
- declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
1896
- declare function useRouteComponentProps(): {
1897
- params: Readonly<Params<string>>;
1898
- loaderData: any;
1899
- actionData: any;
1900
- matches: UIMatch<unknown, unknown>[];
1901
- };
1902
- type RouteComponentProps = ReturnType<typeof useRouteComponentProps>;
1903
- type RouteComponentType = React.ComponentType<RouteComponentProps>;
1904
- declare function WithComponentProps({ children, }: {
1905
- children: React.ReactElement;
1906
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
1907
- declare function withComponentProps(Component: RouteComponentType): () => React.ReactElement<{
1908
- params: Readonly<Params<string>>;
1909
- loaderData: any;
1910
- actionData: any;
1911
- matches: UIMatch<unknown, unknown>[];
1912
- }, string | React.JSXElementConstructor<any>>;
1913
- declare function useHydrateFallbackProps(): {
1914
- params: Readonly<Params<string>>;
1915
- loaderData: any;
1916
- actionData: any;
1917
- };
1918
- type HydrateFallbackProps = ReturnType<typeof useHydrateFallbackProps>;
1919
- type HydrateFallbackType = React.ComponentType<HydrateFallbackProps>;
1920
- declare function WithHydrateFallbackProps({ children, }: {
1921
- children: React.ReactElement;
1922
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
1923
- declare function withHydrateFallbackProps(HydrateFallback: HydrateFallbackType): () => React.ReactElement<{
1924
- params: Readonly<Params<string>>;
1925
- loaderData: any;
1926
- actionData: any;
1927
- }, string | React.JSXElementConstructor<any>>;
1928
- declare function useErrorBoundaryProps(): {
1929
- params: Readonly<Params<string>>;
1930
- loaderData: any;
1931
- actionData: any;
1932
- error: unknown;
1933
- };
1934
- type ErrorBoundaryProps = ReturnType<typeof useErrorBoundaryProps>;
1935
- type ErrorBoundaryType = React.ComponentType<ErrorBoundaryProps>;
1936
- declare function WithErrorBoundaryProps({ children, }: {
1937
- children: React.ReactElement;
1938
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
1939
- declare function withErrorBoundaryProps(ErrorBoundary: ErrorBoundaryType): () => React.ReactElement<{
1940
- params: Readonly<Params<string>>;
1941
- loaderData: any;
1942
- actionData: any;
1943
- error: unknown;
1944
- }, string | React.JSXElementConstructor<any>>;
1945
-
1946
- interface IndexRouteObject {
1947
- caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
1948
- path?: AgnosticIndexRouteObject["path"];
1949
- id?: AgnosticIndexRouteObject["id"];
1950
- middleware?: AgnosticIndexRouteObject["middleware"];
1951
- loader?: AgnosticIndexRouteObject["loader"];
1952
- action?: AgnosticIndexRouteObject["action"];
1953
- hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
1954
- shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
1955
- handle?: AgnosticIndexRouteObject["handle"];
1956
- index: true;
1957
- children?: undefined;
1958
- element?: React.ReactNode | null;
1959
- hydrateFallbackElement?: React.ReactNode | null;
1960
- errorElement?: React.ReactNode | null;
1961
- Component?: React.ComponentType | null;
1962
- HydrateFallback?: React.ComponentType | null;
1963
- ErrorBoundary?: React.ComponentType | null;
1964
- lazy?: LazyRouteDefinition<RouteObject>;
1965
- }
1966
- interface NonIndexRouteObject {
1967
- caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
1968
- path?: AgnosticNonIndexRouteObject["path"];
1969
- id?: AgnosticNonIndexRouteObject["id"];
1970
- middleware?: AgnosticNonIndexRouteObject["middleware"];
1971
- loader?: AgnosticNonIndexRouteObject["loader"];
1972
- action?: AgnosticNonIndexRouteObject["action"];
1973
- hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
1974
- shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
1975
- handle?: AgnosticNonIndexRouteObject["handle"];
1976
- index?: false;
1977
- children?: RouteObject[];
1978
- element?: React.ReactNode | null;
1979
- hydrateFallbackElement?: React.ReactNode | null;
1980
- errorElement?: React.ReactNode | null;
1981
- Component?: React.ComponentType | null;
1982
- HydrateFallback?: React.ComponentType | null;
1983
- ErrorBoundary?: React.ComponentType | null;
1984
- lazy?: LazyRouteDefinition<RouteObject>;
1985
- }
1986
- type RouteObject = IndexRouteObject | NonIndexRouteObject;
1987
- type DataRouteObject = RouteObject & {
1988
- children?: DataRouteObject[];
1989
- id: string;
1990
- };
1991
- interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
1992
- }
1993
- interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
1994
- }
1995
- type PatchRoutesOnNavigationFunctionArgs = AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;
1996
- type PatchRoutesOnNavigationFunction = AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;
1997
- interface DataRouterContextObject extends Omit<NavigationContextObject, "future"> {
1998
- router: Router;
1999
- staticContext?: StaticHandlerContext;
2000
- unstable_onError?: unstable_ClientOnErrorFunction;
2001
- }
2002
- declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
2003
- declare const DataRouterStateContext: React.Context<RouterState | null>;
2004
- type ViewTransitionContextObject = {
2005
- isTransitioning: false;
2006
- } | {
2007
- isTransitioning: true;
2008
- flushSync: boolean;
2009
- currentLocation: Location;
2010
- nextLocation: Location;
2011
- };
2012
- declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
2013
- type FetchersContextObject = Map<string, any>;
2014
- declare const FetchersContext: React.Context<FetchersContextObject>;
2015
- declare const AwaitContext: React.Context<TrackedPromise | null>;
2016
- declare const AwaitContextProvider: (props: React.ComponentProps<typeof AwaitContext.Provider>) => React.FunctionComponentElement<React.ProviderProps<TrackedPromise | null>>;
2017
- interface NavigateOptions {
2018
- /** Replace the current entry in the history stack instead of pushing a new one */
2019
- replace?: boolean;
2020
- /** Adds persistent client side routing state to the next location */
2021
- state?: any;
2022
- /** If you are using {@link https://api.reactrouter.com/v7/functions/react_router.ScrollRestoration.html <ScrollRestoration>}, prevent the scroll position from being reset to the top of the window when navigating */
2023
- preventScrollReset?: boolean;
2024
- /** Defines the relative path behavior for the link. "route" will use the route hierarchy so ".." will remove all URL segments of the current route pattern while "path" will use the URL path so ".." will remove one URL segment. */
2025
- relative?: RelativeRoutingType;
2026
- /** Wraps the initial state update for this navigation in a {@link https://react.dev/reference/react-dom/flushSync ReactDOM.flushSync} call instead of the default {@link https://react.dev/reference/react/startTransition React.startTransition} */
2027
- flushSync?: boolean;
2028
- /** Enables a {@link https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API View Transition} for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the {@link https://api.reactrouter.com/v7/functions/react_router.useViewTransitionState.html useViewTransitionState()} hook. */
2029
- viewTransition?: boolean;
2030
- }
2031
- /**
2032
- * A Navigator is a "location changer"; it's how you get to different locations.
2033
- *
2034
- * Every history instance conforms to the Navigator interface, but the
2035
- * distinction is useful primarily when it comes to the low-level `<Router>` API
2036
- * where both the location and a navigator must be provided separately in order
2037
- * to avoid "tearing" that may occur in a suspense-enabled app if the action
2038
- * and/or location were to be read directly from the history instance.
2039
- */
2040
- interface Navigator {
2041
- createHref: History["createHref"];
2042
- encodeLocation?: History["encodeLocation"];
2043
- go: History["go"];
2044
- push(to: To, state?: any, opts?: NavigateOptions): void;
2045
- replace(to: To, state?: any, opts?: NavigateOptions): void;
2046
- }
2047
- interface NavigationContextObject {
2048
- basename: string;
2049
- navigator: Navigator;
2050
- static: boolean;
2051
- future: {};
2052
- }
2053
- declare const NavigationContext: React.Context<NavigationContextObject>;
2054
- interface LocationContextObject {
2055
- location: Location;
2056
- navigationType: Action;
2057
- }
2058
- declare const LocationContext: React.Context<LocationContextObject>;
2059
- interface RouteContextObject {
2060
- outlet: React.ReactElement | null;
2061
- matches: RouteMatch[];
2062
- isDataRoute: boolean;
2063
- }
2064
- declare const RouteContext: React.Context<RouteContextObject>;
2065
-
2066
- type unstable_ServerInstrumentation = {
2067
- handler?: unstable_InstrumentRequestHandlerFunction;
2068
- route?: unstable_InstrumentRouteFunction;
2069
- };
2070
- type unstable_ClientInstrumentation = {
2071
- router?: unstable_InstrumentRouterFunction;
2072
- route?: unstable_InstrumentRouteFunction;
2073
- };
2074
- type unstable_InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
2075
- type unstable_InstrumentRouterFunction = (router: InstrumentableRouter) => void;
2076
- type unstable_InstrumentRouteFunction = (route: InstrumentableRoute) => void;
2077
- interface GenericInstrumentFunction {
2078
- (handler: () => Promise<void>, info: unknown): Promise<void>;
2079
- }
2080
- type InstrumentableRoute = {
2081
- id: string;
2082
- index: boolean | undefined;
2083
- path: string | undefined;
2084
- instrument(instrumentations: RouteInstrumentations): void;
2085
- };
2086
- type RouteInstrumentations = {
2087
- lazy?: InstrumentLazyFunction;
2088
- "lazy.loader"?: InstrumentLazyFunction;
2089
- "lazy.action"?: InstrumentLazyFunction;
2090
- "lazy.middleware"?: InstrumentLazyFunction;
2091
- middleware?: InstrumentRouteHandlerFunction;
2092
- loader?: InstrumentRouteHandlerFunction;
2093
- action?: InstrumentRouteHandlerFunction;
2094
- };
2095
- type RouteHandlerInstrumentationInfo = Readonly<{
2096
- request: {
2097
- method: string;
2098
- url: string;
2099
- headers: Pick<Headers, "get">;
2100
- };
2101
- params: LoaderFunctionArgs["params"];
2102
- unstable_pattern: string;
2103
- context: Pick<RouterContextProvider, "get">;
2104
- }>;
2105
- interface InstrumentLazyFunction extends GenericInstrumentFunction {
2106
- (handler: () => Promise<void>): Promise<void>;
2107
- }
2108
- interface InstrumentRouteHandlerFunction extends GenericInstrumentFunction {
2109
- (handler: () => Promise<void>, info: RouteHandlerInstrumentationInfo): Promise<void>;
2110
- }
2111
- type InstrumentableRouter = {
2112
- instrument(instrumentations: RouterInstrumentations): void;
2113
- };
2114
- type RouterInstrumentations = {
2115
- navigate?: InstrumentNavigateFunction;
2116
- fetch?: InstrumentFetchFunction;
2117
- };
2118
- type RouterNavigationInstrumentationInfo = Readonly<{
2119
- to: string | number;
2120
- currentUrl: string;
2121
- formMethod?: HTMLFormMethod;
2122
- formEncType?: FormEncType;
2123
- formData?: FormData;
2124
- body?: any;
2125
- }>;
2126
- type RouterFetchInstrumentationInfo = Readonly<{
2127
- href: string;
2128
- currentUrl: string;
2129
- fetcherKey: string;
2130
- formMethod?: HTMLFormMethod;
2131
- formEncType?: FormEncType;
2132
- formData?: FormData;
2133
- body?: any;
2134
- }>;
2135
- interface InstrumentNavigateFunction extends GenericInstrumentFunction {
2136
- (handler: () => Promise<void>, info: RouterNavigationInstrumentationInfo): MaybePromise<void>;
2137
- }
2138
- interface InstrumentFetchFunction extends GenericInstrumentFunction {
2139
- (handler: () => Promise<void>, info: RouterFetchInstrumentationInfo): MaybePromise<void>;
2140
- }
2141
- type InstrumentableRequestHandler = {
2142
- instrument(instrumentations: RequestHandlerInstrumentations): void;
2143
- };
2144
- type RequestHandlerInstrumentations = {
2145
- request?: InstrumentRequestHandlerFunction;
2146
- };
2147
- type RequestHandlerInstrumentationInfo = Readonly<{
2148
- request: {
2149
- method: string;
2150
- url: string;
2151
- headers: Pick<Headers, "get">;
2152
- };
2153
- context: Pick<RouterContextProvider, "get">;
2154
- }>;
2155
- interface InstrumentRequestHandlerFunction extends GenericInstrumentFunction {
2156
- (handler: () => Promise<void>, info: RequestHandlerInstrumentationInfo): MaybePromise<void>;
2157
- }
2158
-
1781
+ declare function MemoryRouter({ basename, children, initialEntries, initialIndex, }: MemoryRouterProps): React.ReactElement;
2159
1782
  /**
2160
- * A Router instance manages all navigation and data loading/mutations
1783
+ * @category Types
2161
1784
  */
2162
- interface Router {
1785
+ interface NavigateProps {
2163
1786
  /**
2164
- * @private
2165
- * PRIVATE - DO NOT USE
2166
- *
2167
- * Return the basename for the router
1787
+ * The path to navigate to. This can be a string or a {@link Path} object
2168
1788
  */
2169
- get basename(): RouterInit["basename"];
1789
+ to: To;
2170
1790
  /**
2171
- * @private
2172
- * PRIVATE - DO NOT USE
2173
- *
2174
- * Return the future config for the router
1791
+ * Whether to replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1792
+ * stack
2175
1793
  */
2176
- get future(): FutureConfig;
1794
+ replace?: boolean;
2177
1795
  /**
2178
- * @private
2179
- * PRIVATE - DO NOT USE
2180
- *
2181
- * Return the current state of the router
1796
+ * State to pass to the new {@link Location} to store in [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state).
2182
1797
  */
2183
- get state(): RouterState;
1798
+ state?: any;
2184
1799
  /**
2185
- * @private
2186
- * PRIVATE - DO NOT USE
2187
- *
2188
- * Return the routes for this router instance
1800
+ * How to interpret relative routing in the `to` prop.
1801
+ * See {@link RelativeRoutingType}.
2189
1802
  */
2190
- get routes(): AgnosticDataRouteObject[];
1803
+ relative?: RelativeRoutingType;
1804
+ }
1805
+ /**
1806
+ * A component-based version of {@link useNavigate} to use in a
1807
+ * [`React.Component` class](https://react.dev/reference/react/Component) where
1808
+ * hooks cannot be used.
1809
+ *
1810
+ * It's recommended to avoid using this component in favor of {@link useNavigate}.
1811
+ *
1812
+ * @example
1813
+ * <Navigate to="/tasks" />
1814
+ *
1815
+ * @public
1816
+ * @category Components
1817
+ * @param props Props
1818
+ * @param {NavigateProps.relative} props.relative n/a
1819
+ * @param {NavigateProps.replace} props.replace n/a
1820
+ * @param {NavigateProps.state} props.state n/a
1821
+ * @param {NavigateProps.to} props.to n/a
1822
+ * @returns {void}
1823
+ *
1824
+ */
1825
+ declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
1826
+ /**
1827
+ * @category Types
1828
+ */
1829
+ interface OutletProps {
2191
1830
  /**
2192
- * @private
2193
- * PRIVATE - DO NOT USE
1831
+ * Provides a context value to the element tree below the outlet. Use when
1832
+ * the parent route needs to provide values to child routes.
2194
1833
  *
2195
- * Return the window associated with the router
2196
- */
2197
- get window(): RouterInit["window"];
2198
- /**
2199
- * @private
2200
- * PRIVATE - DO NOT USE
1834
+ * ```tsx
1835
+ * <Outlet context={myContextValue} />
1836
+ * ```
2201
1837
  *
2202
- * Initialize the router, including adding history listeners and kicking off
2203
- * initial data fetches. Returns a function to cleanup listeners and abort
2204
- * any in-progress loads
1838
+ * Access the context with {@link useOutletContext}.
2205
1839
  */
2206
- initialize(): Router;
2207
- /**
2208
- * @private
2209
- * PRIVATE - DO NOT USE
2210
- *
2211
- * Subscribe to router.state updates
2212
- *
2213
- * @param fn function to call with the new state
2214
- */
2215
- subscribe(fn: RouterSubscriber): () => void;
1840
+ context?: unknown;
1841
+ }
1842
+ /**
1843
+ * Renders the matching child route of a parent route or nothing if no child
1844
+ * route matches.
1845
+ *
1846
+ * @example
1847
+ * import { Outlet } from "react-router";
1848
+ *
1849
+ * export default function SomeParent() {
1850
+ * return (
1851
+ * <div>
1852
+ * <h1>Parent Content</h1>
1853
+ * <Outlet />
1854
+ * </div>
1855
+ * );
1856
+ * }
1857
+ *
1858
+ * @public
1859
+ * @category Components
1860
+ * @param props Props
1861
+ * @param {OutletProps.context} props.context n/a
1862
+ * @returns React element for the rendered outlet or `null` if no child route matches.
1863
+ */
1864
+ declare function Outlet(props: OutletProps): React.ReactElement | null;
1865
+ /**
1866
+ * @category Types
1867
+ */
1868
+ interface PathRouteProps {
2216
1869
  /**
2217
- * @private
2218
- * PRIVATE - DO NOT USE
2219
- *
2220
- * Enable scroll restoration behavior in the router
2221
- *
2222
- * @param savedScrollPositions Object that will manage positions, in case
2223
- * it's being restored from sessionStorage
2224
- * @param getScrollPosition Function to get the active Y scroll position
2225
- * @param getKey Function to get the key to use for restoration
1870
+ * Whether the path should be case-sensitive. Defaults to `false`.
2226
1871
  */
2227
- enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
1872
+ caseSensitive?: NonIndexRouteObject["caseSensitive"];
2228
1873
  /**
2229
- * @private
2230
- * PRIVATE - DO NOT USE
2231
- *
2232
- * Navigate forward/backward in the history stack
2233
- * @param to Delta to move in the history stack
1874
+ * The path pattern to match. If unspecified or empty, then this becomes a
1875
+ * layout route.
2234
1876
  */
2235
- navigate(to: number): Promise<void>;
1877
+ path?: NonIndexRouteObject["path"];
2236
1878
  /**
2237
- * Navigate to the given path
2238
- * @param to Path to navigate to
2239
- * @param opts Navigation options (method, submission, etc.)
1879
+ * The unique identifier for this route (for use with {@link DataRouter}s)
2240
1880
  */
2241
- navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
1881
+ id?: NonIndexRouteObject["id"];
2242
1882
  /**
2243
- * @private
2244
- * PRIVATE - DO NOT USE
2245
- *
2246
- * Trigger a fetcher load/submission
2247
- *
2248
- * @param key Fetcher key
2249
- * @param routeId Route that owns the fetcher
2250
- * @param href href to fetch
2251
- * @param opts Fetcher options, (method, submission, etc.)
1883
+ * A function that returns a promise that resolves to the route object.
1884
+ * Used for code-splitting routes.
1885
+ * See [`lazy`](../../start/data/route-object#lazy).
2252
1886
  */
2253
- fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
1887
+ lazy?: LazyRouteFunction<NonIndexRouteObject>;
2254
1888
  /**
2255
- * @private
2256
- * PRIVATE - DO NOT USE
2257
- *
2258
- * Trigger a revalidation of all current route loaders and fetcher loads
1889
+ * The route middleware.
1890
+ * See [`middleware`](../../start/data/route-object#middleware).
2259
1891
  */
2260
- revalidate(): Promise<void>;
1892
+ middleware?: NonIndexRouteObject["middleware"];
2261
1893
  /**
2262
- * @private
2263
- * PRIVATE - DO NOT USE
2264
- *
2265
- * Utility function to create an href for the given location
2266
- * @param location
1894
+ * The route loader.
1895
+ * See [`loader`](../../start/data/route-object#loader).
2267
1896
  */
2268
- createHref(location: Location | URL): string;
1897
+ loader?: NonIndexRouteObject["loader"];
2269
1898
  /**
2270
- * @private
2271
- * PRIVATE - DO NOT USE
2272
- *
2273
- * Utility function to URL encode a destination path according to the internal
2274
- * history implementation
2275
- * @param to
1899
+ * The route action.
1900
+ * See [`action`](../../start/data/route-object#action).
2276
1901
  */
2277
- encodeLocation(to: To): Path;
1902
+ action?: NonIndexRouteObject["action"];
1903
+ hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
2278
1904
  /**
2279
- * @private
2280
- * PRIVATE - DO NOT USE
2281
- *
2282
- * Get/create a fetcher for the given key
2283
- * @param key
1905
+ * The route shouldRevalidate function.
1906
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
2284
1907
  */
2285
- getFetcher<TData = any>(key: string): Fetcher<TData>;
1908
+ shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
2286
1909
  /**
2287
- * @internal
2288
- * PRIVATE - DO NOT USE
2289
- *
2290
- * Reset the fetcher for a given key
2291
- * @param key
1910
+ * The route handle.
2292
1911
  */
2293
- resetFetcher(key: string, opts?: {
2294
- reason?: unknown;
2295
- }): void;
1912
+ handle?: NonIndexRouteObject["handle"];
2296
1913
  /**
2297
- * @private
2298
- * PRIVATE - DO NOT USE
2299
- *
2300
- * Delete the fetcher for a given key
2301
- * @param key
1914
+ * Whether this is an index route.
2302
1915
  */
2303
- deleteFetcher(key: string): void;
1916
+ index?: false;
2304
1917
  /**
2305
- * @private
2306
- * PRIVATE - DO NOT USE
2307
- *
2308
- * Cleanup listeners and abort any in-progress loads
1918
+ * Child Route components
2309
1919
  */
2310
- dispose(): void;
1920
+ children?: React.ReactNode;
2311
1921
  /**
2312
- * @private
2313
- * PRIVATE - DO NOT USE
2314
- *
2315
- * Get a navigation blocker
2316
- * @param key The identifier for the blocker
2317
- * @param fn The blocker function implementation
1922
+ * The React element to render when this Route matches.
1923
+ * Mutually exclusive with `Component`.
2318
1924
  */
2319
- getBlocker(key: string, fn: BlockerFunction): Blocker;
1925
+ element?: React.ReactNode | null;
2320
1926
  /**
2321
- * @private
2322
- * PRIVATE - DO NOT USE
2323
- *
2324
- * Delete a navigation blocker
2325
- * @param key The identifier for the blocker
1927
+ * The React element to render while this router is loading data.
1928
+ * Mutually exclusive with `HydrateFallback`.
2326
1929
  */
2327
- deleteBlocker(key: string): void;
1930
+ hydrateFallbackElement?: React.ReactNode | null;
2328
1931
  /**
2329
- * @private
2330
- * PRIVATE DO NOT USE
2331
- *
2332
- * Patch additional children routes into an existing parent route
2333
- * @param routeId The parent route id or a callback function accepting `patch`
2334
- * to perform batch patching
2335
- * @param children The additional children routes
2336
- * @param unstable_allowElementMutations Allow mutation or route elements on
2337
- * existing routes. Intended for RSC-usage
2338
- * only.
1932
+ * The React element to render at this route if an error occurs.
1933
+ * Mutually exclusive with `ErrorBoundary`.
2339
1934
  */
2340
- patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
1935
+ errorElement?: React.ReactNode | null;
2341
1936
  /**
2342
- * @private
2343
- * PRIVATE - DO NOT USE
2344
- *
2345
- * HMR needs to pass in-flight route updates to React Router
2346
- * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
1937
+ * The React Component to render when this route matches.
1938
+ * Mutually exclusive with `element`.
2347
1939
  */
2348
- _internalSetRoutes(routes: AgnosticRouteObject[]): void;
1940
+ Component?: React.ComponentType | null;
2349
1941
  /**
2350
- * @private
2351
- * PRIVATE - DO NOT USE
2352
- *
2353
- * Cause subscribers to re-render. This is used to force a re-render.
1942
+ * The React Component to render while this router is loading data.
1943
+ * Mutually exclusive with `hydrateFallbackElement`.
2354
1944
  */
2355
- _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
1945
+ HydrateFallback?: React.ComponentType | null;
2356
1946
  /**
2357
- * @private
2358
- * PRIVATE - DO NOT USE
2359
- *
2360
- * Internal fetch AbortControllers accessed by unit tests
1947
+ * The React Component to render at this route if an error occurs.
1948
+ * Mutually exclusive with `errorElement`.
2361
1949
  */
2362
- _internalFetchControllers: Map<string, AbortController>;
1950
+ ErrorBoundary?: React.ComponentType | null;
2363
1951
  }
2364
1952
  /**
2365
- * State maintained internally by the router. During a navigation, all states
2366
- * reflect the "old" location unless otherwise noted.
1953
+ * @category Types
2367
1954
  */
2368
- interface RouterState {
1955
+ interface LayoutRouteProps extends PathRouteProps {
1956
+ }
1957
+ /**
1958
+ * @category Types
1959
+ */
1960
+ interface IndexRouteProps {
2369
1961
  /**
2370
- * The action of the most recent navigation
1962
+ * Whether the path should be case-sensitive. Defaults to `false`.
2371
1963
  */
2372
- historyAction: Action;
1964
+ caseSensitive?: IndexRouteObject["caseSensitive"];
2373
1965
  /**
2374
- * The current location reflected by the router
1966
+ * The path pattern to match. If unspecified or empty, then this becomes a
1967
+ * layout route.
2375
1968
  */
2376
- location: Location;
1969
+ path?: IndexRouteObject["path"];
2377
1970
  /**
2378
- * The current set of route matches
1971
+ * The unique identifier for this route (for use with {@link DataRouter}s)
2379
1972
  */
2380
- matches: AgnosticDataRouteMatch[];
1973
+ id?: IndexRouteObject["id"];
2381
1974
  /**
2382
- * Tracks whether we've completed our initial data load
1975
+ * A function that returns a promise that resolves to the route object.
1976
+ * Used for code-splitting routes.
1977
+ * See [`lazy`](../../start/data/route-object#lazy).
2383
1978
  */
2384
- initialized: boolean;
1979
+ lazy?: LazyRouteFunction<IndexRouteObject>;
2385
1980
  /**
2386
- * Current scroll position we should start at for a new view
2387
- * - number -> scroll position to restore to
2388
- * - false -> do not restore scroll at all (used during submissions/revalidations)
2389
- * - null -> don't have a saved position, scroll to hash or top of page
1981
+ * The route middleware.
1982
+ * See [`middleware`](../../start/data/route-object#middleware).
2390
1983
  */
2391
- restoreScrollPosition: number | false | null;
1984
+ middleware?: IndexRouteObject["middleware"];
2392
1985
  /**
2393
- * Indicate whether this navigation should skip resetting the scroll position
2394
- * if we are unable to restore the scroll position
1986
+ * The route loader.
1987
+ * See [`loader`](../../start/data/route-object#loader).
2395
1988
  */
2396
- preventScrollReset: boolean;
1989
+ loader?: IndexRouteObject["loader"];
2397
1990
  /**
2398
- * Tracks the state of the current navigation
1991
+ * The route action.
1992
+ * See [`action`](../../start/data/route-object#action).
2399
1993
  */
2400
- navigation: Navigation;
1994
+ action?: IndexRouteObject["action"];
1995
+ hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
2401
1996
  /**
2402
- * Tracks any in-progress revalidations
1997
+ * The route shouldRevalidate function.
1998
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
2403
1999
  */
2404
- revalidation: RevalidationState;
2000
+ shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
2405
2001
  /**
2406
- * Data from the loaders for the current matches
2002
+ * The route handle.
2407
2003
  */
2408
- loaderData: RouteData;
2004
+ handle?: IndexRouteObject["handle"];
2409
2005
  /**
2410
- * Data from the action for the current matches
2006
+ * Whether this is an index route.
2411
2007
  */
2412
- actionData: RouteData | null;
2008
+ index: true;
2413
2009
  /**
2414
- * Errors caught from loaders for the current matches
2010
+ * Child Route components
2415
2011
  */
2416
- errors: RouteData | null;
2012
+ children?: undefined;
2417
2013
  /**
2418
- * Map of current fetchers
2014
+ * The React element to render when this Route matches.
2015
+ * Mutually exclusive with `Component`.
2419
2016
  */
2420
- fetchers: Map<string, Fetcher>;
2017
+ element?: React.ReactNode | null;
2421
2018
  /**
2422
- * Map of current blockers
2019
+ * The React element to render while this router is loading data.
2020
+ * Mutually exclusive with `HydrateFallback`.
2423
2021
  */
2424
- blockers: Map<string, Blocker>;
2022
+ hydrateFallbackElement?: React.ReactNode | null;
2023
+ /**
2024
+ * The React element to render at this route if an error occurs.
2025
+ * Mutually exclusive with `ErrorBoundary`.
2026
+ */
2027
+ errorElement?: React.ReactNode | null;
2028
+ /**
2029
+ * The React Component to render when this route matches.
2030
+ * Mutually exclusive with `element`.
2031
+ */
2032
+ Component?: React.ComponentType | null;
2033
+ /**
2034
+ * The React Component to render while this router is loading data.
2035
+ * Mutually exclusive with `hydrateFallbackElement`.
2036
+ */
2037
+ HydrateFallback?: React.ComponentType | null;
2038
+ /**
2039
+ * The React Component to render at this route if an error occurs.
2040
+ * Mutually exclusive with `errorElement`.
2041
+ */
2042
+ ErrorBoundary?: React.ComponentType | null;
2425
2043
  }
2044
+ type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
2426
2045
  /**
2427
- * Data that can be passed into hydrate a Router from SSR
2046
+ * Configures an element to render when a pattern matches the current location.
2047
+ * It must be rendered within a {@link Routes} element. Note that these routes
2048
+ * do not participate in data loading, actions, code splitting, or any other
2049
+ * route module features.
2050
+ *
2051
+ * @example
2052
+ * // Usually used in a declarative router
2053
+ * function App() {
2054
+ * return (
2055
+ * <BrowserRouter>
2056
+ * <Routes>
2057
+ * <Route index element={<StepOne />} />
2058
+ * <Route path="step-2" element={<StepTwo />} />
2059
+ * <Route path="step-3" element={<StepThree />} />
2060
+ * </Routes>
2061
+ * </BrowserRouter>
2062
+ * );
2063
+ * }
2064
+ *
2065
+ * // But can be used with a data router as well if you prefer the JSX notation
2066
+ * const routes = createRoutesFromElements(
2067
+ * <>
2068
+ * <Route index loader={step1Loader} Component={StepOne} />
2069
+ * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
2070
+ * <Route path="step-3" loader={step3Loader} Component={StepThree} />
2071
+ * </>
2072
+ * );
2073
+ *
2074
+ * const router = createBrowserRouter(routes);
2075
+ *
2076
+ * function App() {
2077
+ * return <RouterProvider router={router} />;
2078
+ * }
2079
+ *
2080
+ * @public
2081
+ * @category Components
2082
+ * @param props Props
2083
+ * @param {PathRouteProps.action} props.action n/a
2084
+ * @param {PathRouteProps.caseSensitive} props.caseSensitive n/a
2085
+ * @param {PathRouteProps.Component} props.Component n/a
2086
+ * @param {PathRouteProps.children} props.children n/a
2087
+ * @param {PathRouteProps.element} props.element n/a
2088
+ * @param {PathRouteProps.ErrorBoundary} props.ErrorBoundary n/a
2089
+ * @param {PathRouteProps.errorElement} props.errorElement n/a
2090
+ * @param {PathRouteProps.handle} props.handle n/a
2091
+ * @param {PathRouteProps.HydrateFallback} props.HydrateFallback n/a
2092
+ * @param {PathRouteProps.hydrateFallbackElement} props.hydrateFallbackElement n/a
2093
+ * @param {PathRouteProps.id} props.id n/a
2094
+ * @param {PathRouteProps.index} props.index n/a
2095
+ * @param {PathRouteProps.lazy} props.lazy n/a
2096
+ * @param {PathRouteProps.loader} props.loader n/a
2097
+ * @param {PathRouteProps.path} props.path n/a
2098
+ * @param {PathRouteProps.shouldRevalidate} props.shouldRevalidate n/a
2099
+ * @returns {void}
2428
2100
  */
2429
- type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
2101
+ declare function Route(props: RouteProps): React.ReactElement | null;
2430
2102
  /**
2431
- * Future flags to toggle new feature behavior
2103
+ * @category Types
2432
2104
  */
2433
- interface FutureConfig {
2105
+ interface RouterProps {
2106
+ /**
2107
+ * The base path for the application. This is prepended to all locations
2108
+ */
2109
+ basename?: string;
2110
+ /**
2111
+ * Nested {@link Route} elements describing the route tree
2112
+ */
2113
+ children?: React.ReactNode;
2114
+ /**
2115
+ * The location to match against. Defaults to the current location.
2116
+ * This can be a string or a {@link Location} object.
2117
+ */
2118
+ location: Partial<Location> | string;
2119
+ /**
2120
+ * The type of navigation that triggered this `location` change.
2121
+ * Defaults to {@link NavigationType.Pop}.
2122
+ */
2123
+ navigationType?: Action;
2124
+ /**
2125
+ * The navigator to use for navigation. This is usually a history object
2126
+ * or a custom navigator that implements the {@link Navigator} interface.
2127
+ */
2128
+ navigator: Navigator;
2129
+ /**
2130
+ * Whether this router is static or not (used for SSR). If `true`, the router
2131
+ * will not be reactive to location changes.
2132
+ */
2133
+ static?: boolean;
2434
2134
  }
2435
2135
  /**
2436
- * Initialization options for createRouter
2136
+ * Provides location context for the rest of the app.
2137
+ *
2138
+ * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
2139
+ * router that is more specific to your environment such as a {@link BrowserRouter}
2140
+ * in web browsers or a {@link ServerRouter} for server rendering.
2141
+ *
2142
+ * @public
2143
+ * @category Declarative Routers
2144
+ * @mode declarative
2145
+ * @param props Props
2146
+ * @param {RouterProps.basename} props.basename n/a
2147
+ * @param {RouterProps.children} props.children n/a
2148
+ * @param {RouterProps.location} props.location n/a
2149
+ * @param {RouterProps.navigationType} props.navigationType n/a
2150
+ * @param {RouterProps.navigator} props.navigator n/a
2151
+ * @param {RouterProps.static} props.static n/a
2152
+ * @returns React element for the rendered router or `null` if the location does
2153
+ * not match the {@link props.basename}
2437
2154
  */
2438
- interface RouterInit {
2439
- routes: AgnosticRouteObject[];
2440
- history: History;
2441
- basename?: string;
2442
- getContext?: () => MaybePromise<RouterContextProvider>;
2443
- unstable_instrumentations?: unstable_ClientInstrumentation[];
2444
- mapRouteProperties?: MapRoutePropertiesFunction;
2445
- future?: Partial<FutureConfig>;
2446
- hydrationRouteProperties?: string[];
2447
- hydrationData?: HydrationState;
2448
- window?: Window;
2449
- dataStrategy?: DataStrategyFunction;
2450
- patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
2451
- }
2155
+ declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, }: RouterProps): React.ReactElement | null;
2452
2156
  /**
2453
- * State returned from a server-side query() call
2157
+ * @category Types
2454
2158
  */
2455
- interface StaticHandlerContext {
2456
- basename: Router["basename"];
2457
- location: RouterState["location"];
2458
- matches: RouterState["matches"];
2459
- loaderData: RouterState["loaderData"];
2460
- actionData: RouterState["actionData"];
2461
- errors: RouterState["errors"];
2462
- statusCode: number;
2463
- loaderHeaders: Record<string, Headers>;
2464
- actionHeaders: Record<string, Headers>;
2465
- _deepestRenderedBoundaryId?: string | null;
2159
+ interface RoutesProps {
2160
+ /**
2161
+ * Nested {@link Route} elements
2162
+ */
2163
+ children?: React.ReactNode;
2164
+ /**
2165
+ * The {@link Location} to match against. Defaults to the current location.
2166
+ */
2167
+ location?: Partial<Location> | string;
2466
2168
  }
2467
2169
  /**
2468
- * A StaticHandler instance manages a singular SSR navigation/fetch event
2170
+ * Renders a branch of {@link Route | `<Route>`s} that best matches the current
2171
+ * location. Note that these routes do not participate in [data loading](../../start/framework/route-module#loader),
2172
+ * [`action`](../../start/framework/route-module#action), code splitting, or
2173
+ * any other [route module](../../start/framework/route-module) features.
2174
+ *
2175
+ * @example
2176
+ * import { Route, Routes } from "react-router";
2177
+ *
2178
+ * <Routes>
2179
+ * <Route index element={<StepOne />} />
2180
+ * <Route path="step-2" element={<StepTwo />} />
2181
+ * <Route path="step-3" element={<StepThree />}>
2182
+ * </Routes>
2183
+ *
2184
+ * @public
2185
+ * @category Components
2186
+ * @param props Props
2187
+ * @param {RoutesProps.children} props.children n/a
2188
+ * @param {RoutesProps.location} props.location n/a
2189
+ * @returns React element for the rendered routes or `null` if no route matches
2469
2190
  */
2470
- interface StaticHandler {
2471
- dataRoutes: AgnosticDataRouteObject[];
2472
- query(request: Request, opts?: {
2473
- requestContext?: unknown;
2474
- filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
2475
- skipLoaderErrorBubbling?: boolean;
2476
- skipRevalidation?: boolean;
2477
- dataStrategy?: DataStrategyFunction<unknown>;
2478
- generateMiddlewareResponse?: (query: (r: Request, args?: {
2479
- filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
2480
- }) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
2481
- }): Promise<StaticHandlerContext | Response>;
2482
- queryRoute(request: Request, opts?: {
2483
- routeId?: string;
2484
- requestContext?: unknown;
2485
- dataStrategy?: DataStrategyFunction<unknown>;
2486
- generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
2487
- }): Promise<any>;
2191
+ declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
2192
+ interface AwaitResolveRenderFunction<Resolve = any> {
2193
+ (data: Awaited<Resolve>): React.ReactNode;
2488
2194
  }
2489
- type ViewTransitionOpts = {
2195
+ /**
2196
+ * @category Types
2197
+ */
2198
+ interface AwaitProps<Resolve> {
2199
+ /**
2200
+ * When using a function, the resolved value is provided as the parameter.
2201
+ *
2202
+ * ```tsx [2]
2203
+ * <Await resolve={reviewsPromise}>
2204
+ * {(resolvedReviews) => <Reviews items={resolvedReviews} />}
2205
+ * </Await>
2206
+ * ```
2207
+ *
2208
+ * When using React elements, {@link useAsyncValue} will provide the
2209
+ * resolved value:
2210
+ *
2211
+ * ```tsx [2]
2212
+ * <Await resolve={reviewsPromise}>
2213
+ * <Reviews />
2214
+ * </Await>
2215
+ *
2216
+ * function Reviews() {
2217
+ * const resolvedReviews = useAsyncValue();
2218
+ * return <div>...</div>;
2219
+ * }
2220
+ * ```
2221
+ */
2222
+ children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
2223
+ /**
2224
+ * The error element renders instead of the `children` when the [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
2225
+ * rejects.
2226
+ *
2227
+ * ```tsx
2228
+ * <Await
2229
+ * errorElement={<div>Oops</div>}
2230
+ * resolve={reviewsPromise}
2231
+ * >
2232
+ * <Reviews />
2233
+ * </Await>
2234
+ * ```
2235
+ *
2236
+ * To provide a more contextual error, you can use the {@link useAsyncError} in a
2237
+ * child component
2238
+ *
2239
+ * ```tsx
2240
+ * <Await
2241
+ * errorElement={<ReviewsError />}
2242
+ * resolve={reviewsPromise}
2243
+ * >
2244
+ * <Reviews />
2245
+ * </Await>
2246
+ *
2247
+ * function ReviewsError() {
2248
+ * const error = useAsyncError();
2249
+ * return <div>Error loading reviews: {error.message}</div>;
2250
+ * }
2251
+ * ```
2252
+ *
2253
+ * If you do not provide an `errorElement`, the rejected value will bubble up
2254
+ * to the nearest route-level [`ErrorBoundary`](../../start/framework/route-module#errorboundary)
2255
+ * and be accessible via the {@link useRouteError} hook.
2256
+ */
2257
+ errorElement?: React.ReactNode;
2258
+ /**
2259
+ * Takes a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
2260
+ * returned from a [`loader`](../../start/framework/route-module#loader) to be
2261
+ * resolved and rendered.
2262
+ *
2263
+ * ```tsx
2264
+ * import { Await, useLoaderData } from "react-router";
2265
+ *
2266
+ * export async function loader() {
2267
+ * let reviews = getReviews(); // not awaited
2268
+ * let book = await getBook();
2269
+ * return {
2270
+ * book,
2271
+ * reviews, // this is a promise
2272
+ * };
2273
+ * }
2274
+ *
2275
+ * export default function Book() {
2276
+ * const {
2277
+ * book,
2278
+ * reviews, // this is the same promise
2279
+ * } = useLoaderData();
2280
+ *
2281
+ * return (
2282
+ * <div>
2283
+ * <h1>{book.title}</h1>
2284
+ * <p>{book.description}</p>
2285
+ * <React.Suspense fallback={<ReviewsSkeleton />}>
2286
+ * <Await
2287
+ * // and is the promise we pass to Await
2288
+ * resolve={reviews}
2289
+ * >
2290
+ * <Reviews />
2291
+ * </Await>
2292
+ * </React.Suspense>
2293
+ * </div>
2294
+ * );
2295
+ * }
2296
+ * ```
2297
+ */
2298
+ resolve: Resolve;
2299
+ }
2300
+ /**
2301
+ * Used to render promise values with automatic error handling.
2302
+ *
2303
+ * **Note:** `<Await>` expects to be rendered inside a [`<React.Suspense>`](https://react.dev/reference/react/Suspense)
2304
+ *
2305
+ * @example
2306
+ * import { Await, useLoaderData } from "react-router";
2307
+ *
2308
+ * export async function loader() {
2309
+ * // not awaited
2310
+ * const reviews = getReviews();
2311
+ * // awaited (blocks the transition)
2312
+ * const book = await fetch("/api/book").then((res) => res.json());
2313
+ * return { book, reviews };
2314
+ * }
2315
+ *
2316
+ * function Book() {
2317
+ * const { book, reviews } = useLoaderData();
2318
+ * return (
2319
+ * <div>
2320
+ * <h1>{book.title}</h1>
2321
+ * <p>{book.description}</p>
2322
+ * <React.Suspense fallback={<ReviewsSkeleton />}>
2323
+ * <Await
2324
+ * resolve={reviews}
2325
+ * errorElement={
2326
+ * <div>Could not load reviews 😬</div>
2327
+ * }
2328
+ * children={(resolvedReviews) => (
2329
+ * <Reviews items={resolvedReviews} />
2330
+ * )}
2331
+ * />
2332
+ * </React.Suspense>
2333
+ * </div>
2334
+ * );
2335
+ * }
2336
+ *
2337
+ * @public
2338
+ * @category Components
2339
+ * @mode framework
2340
+ * @mode data
2341
+ * @param props Props
2342
+ * @param {AwaitProps.children} props.children n/a
2343
+ * @param {AwaitProps.errorElement} props.errorElement n/a
2344
+ * @param {AwaitProps.resolve} props.resolve n/a
2345
+ * @returns React element for the rendered awaited value
2346
+ */
2347
+ declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
2348
+ /**
2349
+ * Creates a route config from a React "children" object, which is usually
2350
+ * either a `<Route>` element or an array of them. Used internally by
2351
+ * `<Routes>` to create a route config from its children.
2352
+ *
2353
+ * @category Utils
2354
+ * @mode data
2355
+ * @param children The React children to convert into a route config
2356
+ * @param parentPath The path of the parent route, used to generate unique IDs.
2357
+ * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
2358
+ */
2359
+ declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
2360
+ /**
2361
+ * Create route objects from JSX elements instead of arrays of objects.
2362
+ *
2363
+ * @example
2364
+ * const routes = createRoutesFromElements(
2365
+ * <>
2366
+ * <Route index loader={step1Loader} Component={StepOne} />
2367
+ * <Route path="step-2" loader={step2Loader} Component={StepTwo} />
2368
+ * <Route path="step-3" loader={step3Loader} Component={StepThree} />
2369
+ * </>
2370
+ * );
2371
+ *
2372
+ * const router = createBrowserRouter(routes);
2373
+ *
2374
+ * function App() {
2375
+ * return <RouterProvider router={router} />;
2376
+ * }
2377
+ *
2378
+ * @name createRoutesFromElements
2379
+ * @public
2380
+ * @category Utils
2381
+ * @mode data
2382
+ * @param children The React children to convert into a route config
2383
+ * @param parentPath The path of the parent route, used to generate unique IDs.
2384
+ * This is used for internal recursion and is not intended to be used by the
2385
+ * application developer.
2386
+ * @returns An array of {@link RouteObject}s that can be used with a {@link DataRouter}
2387
+ */
2388
+ declare const createRoutesFromElements: typeof createRoutesFromChildren;
2389
+ /**
2390
+ * Renders the result of {@link matchRoutes} into a React element.
2391
+ *
2392
+ * @public
2393
+ * @category Utils
2394
+ * @param matches The array of {@link RouteMatch | route matches} to render
2395
+ * @returns A React element that renders the matched routes or `null` if no matches
2396
+ */
2397
+ declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
2398
+ declare function useRouteComponentProps(): {
2399
+ params: Readonly<Params<string>>;
2400
+ loaderData: any;
2401
+ actionData: any;
2402
+ matches: UIMatch<unknown, unknown>[];
2403
+ };
2404
+ type RouteComponentProps = ReturnType<typeof useRouteComponentProps>;
2405
+ type RouteComponentType = React.ComponentType<RouteComponentProps>;
2406
+ declare function WithComponentProps({ children, }: {
2407
+ children: React.ReactElement;
2408
+ }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
2409
+ declare function withComponentProps(Component: RouteComponentType): () => React.ReactElement<{
2410
+ params: Readonly<Params<string>>;
2411
+ loaderData: any;
2412
+ actionData: any;
2413
+ matches: UIMatch<unknown, unknown>[];
2414
+ }, string | React.JSXElementConstructor<any>>;
2415
+ declare function useHydrateFallbackProps(): {
2416
+ params: Readonly<Params<string>>;
2417
+ loaderData: any;
2418
+ actionData: any;
2419
+ };
2420
+ type HydrateFallbackProps = ReturnType<typeof useHydrateFallbackProps>;
2421
+ type HydrateFallbackType = React.ComponentType<HydrateFallbackProps>;
2422
+ declare function WithHydrateFallbackProps({ children, }: {
2423
+ children: React.ReactElement;
2424
+ }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
2425
+ declare function withHydrateFallbackProps(HydrateFallback: HydrateFallbackType): () => React.ReactElement<{
2426
+ params: Readonly<Params<string>>;
2427
+ loaderData: any;
2428
+ actionData: any;
2429
+ }, string | React.JSXElementConstructor<any>>;
2430
+ declare function useErrorBoundaryProps(): {
2431
+ params: Readonly<Params<string>>;
2432
+ loaderData: any;
2433
+ actionData: any;
2434
+ error: unknown;
2435
+ };
2436
+ type ErrorBoundaryProps = ReturnType<typeof useErrorBoundaryProps>;
2437
+ type ErrorBoundaryType = React.ComponentType<ErrorBoundaryProps>;
2438
+ declare function WithErrorBoundaryProps({ children, }: {
2439
+ children: React.ReactElement;
2440
+ }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
2441
+ declare function withErrorBoundaryProps(ErrorBoundary: ErrorBoundaryType): () => React.ReactElement<{
2442
+ params: Readonly<Params<string>>;
2443
+ loaderData: any;
2444
+ actionData: any;
2445
+ error: unknown;
2446
+ }, string | React.JSXElementConstructor<any>>;
2447
+
2448
+ interface IndexRouteObject {
2449
+ caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
2450
+ path?: AgnosticIndexRouteObject["path"];
2451
+ id?: AgnosticIndexRouteObject["id"];
2452
+ middleware?: AgnosticIndexRouteObject["middleware"];
2453
+ loader?: AgnosticIndexRouteObject["loader"];
2454
+ action?: AgnosticIndexRouteObject["action"];
2455
+ hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
2456
+ shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
2457
+ handle?: AgnosticIndexRouteObject["handle"];
2458
+ index: true;
2459
+ children?: undefined;
2460
+ element?: React.ReactNode | null;
2461
+ hydrateFallbackElement?: React.ReactNode | null;
2462
+ errorElement?: React.ReactNode | null;
2463
+ Component?: React.ComponentType | null;
2464
+ HydrateFallback?: React.ComponentType | null;
2465
+ ErrorBoundary?: React.ComponentType | null;
2466
+ lazy?: LazyRouteDefinition<RouteObject>;
2467
+ }
2468
+ interface NonIndexRouteObject {
2469
+ caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
2470
+ path?: AgnosticNonIndexRouteObject["path"];
2471
+ id?: AgnosticNonIndexRouteObject["id"];
2472
+ middleware?: AgnosticNonIndexRouteObject["middleware"];
2473
+ loader?: AgnosticNonIndexRouteObject["loader"];
2474
+ action?: AgnosticNonIndexRouteObject["action"];
2475
+ hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
2476
+ shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
2477
+ handle?: AgnosticNonIndexRouteObject["handle"];
2478
+ index?: false;
2479
+ children?: RouteObject[];
2480
+ element?: React.ReactNode | null;
2481
+ hydrateFallbackElement?: React.ReactNode | null;
2482
+ errorElement?: React.ReactNode | null;
2483
+ Component?: React.ComponentType | null;
2484
+ HydrateFallback?: React.ComponentType | null;
2485
+ ErrorBoundary?: React.ComponentType | null;
2486
+ lazy?: LazyRouteDefinition<RouteObject>;
2487
+ }
2488
+ type RouteObject = IndexRouteObject | NonIndexRouteObject;
2489
+ type DataRouteObject = RouteObject & {
2490
+ children?: DataRouteObject[];
2491
+ id: string;
2492
+ };
2493
+ interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
2494
+ }
2495
+ interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
2496
+ }
2497
+ type PatchRoutesOnNavigationFunctionArgs = AgnosticPatchRoutesOnNavigationFunctionArgs<RouteObject, RouteMatch>;
2498
+ type PatchRoutesOnNavigationFunction = AgnosticPatchRoutesOnNavigationFunction<RouteObject, RouteMatch>;
2499
+ interface DataRouterContextObject extends Omit<NavigationContextObject, "future"> {
2500
+ router: Router$1;
2501
+ staticContext?: StaticHandlerContext;
2502
+ unstable_onError?: unstable_ClientOnErrorFunction;
2503
+ }
2504
+ declare const DataRouterContext: React.Context<DataRouterContextObject | null>;
2505
+ declare const DataRouterStateContext: React.Context<RouterState | null>;
2506
+ type ViewTransitionContextObject = {
2507
+ isTransitioning: false;
2508
+ } | {
2509
+ isTransitioning: true;
2510
+ flushSync: boolean;
2490
2511
  currentLocation: Location;
2491
2512
  nextLocation: Location;
2492
2513
  };
2493
- /**
2494
- * Subscriber function signature for changes to router state
2495
- */
2496
- interface RouterSubscriber {
2497
- (state: RouterState, opts: {
2498
- deletedFetchers: string[];
2499
- viewTransitionOpts?: ViewTransitionOpts;
2500
- flushSync: boolean;
2501
- }): void;
2502
- }
2503
- /**
2504
- * Function signature for determining the key to be used in scroll restoration
2505
- * for a given location
2506
- */
2507
- interface GetScrollRestorationKeyFunction {
2508
- (location: Location, matches: UIMatch[]): string | null;
2509
- }
2510
- /**
2511
- * Function signature for determining the current scroll position
2512
- */
2513
- interface GetScrollPositionFunction {
2514
- (): number;
2515
- }
2516
- /**
2517
- * - "route": relative to the route hierarchy so `..` means remove all segments
2518
- * of the current route even if it has many. For example, a `route("posts/:id")`
2519
- * would have both `:id` and `posts` removed from the url.
2520
- * - "path": relative to the pathname so `..` means remove one segment of the
2521
- * pathname. For example, a `route("posts/:id")` would have only `:id` removed
2522
- * from the url.
2523
- */
2524
- type RelativeRoutingType = "route" | "path";
2525
- type BaseNavigateOrFetchOptions = {
2514
+ declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>;
2515
+ type FetchersContextObject = Map<string, any>;
2516
+ declare const FetchersContext: React.Context<FetchersContextObject>;
2517
+ declare const AwaitContext: React.Context<TrackedPromise | null>;
2518
+ declare const AwaitContextProvider: (props: React.ComponentProps<typeof AwaitContext.Provider>) => React.FunctionComponentElement<React.ProviderProps<TrackedPromise | null>>;
2519
+ interface NavigateOptions {
2520
+ /** Replace the current entry in the history stack instead of pushing a new one */
2521
+ replace?: boolean;
2522
+ /** Adds persistent client side routing state to the next location */
2523
+ state?: any;
2524
+ /** If you are using {@link https://api.reactrouter.com/v7/functions/react_router.ScrollRestoration.html <ScrollRestoration>}, prevent the scroll position from being reset to the top of the window when navigating */
2526
2525
  preventScrollReset?: boolean;
2526
+ /** Defines the relative path behavior for the link. "route" will use the route hierarchy so ".." will remove all URL segments of the current route pattern while "path" will use the URL path so ".." will remove one URL segment. */
2527
2527
  relative?: RelativeRoutingType;
2528
+ /** Wraps the initial state update for this navigation in a {@link https://react.dev/reference/react-dom/flushSync ReactDOM.flushSync} call instead of the default {@link https://react.dev/reference/react/startTransition React.startTransition} */
2528
2529
  flushSync?: boolean;
2529
- };
2530
- type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
2531
- replace?: boolean;
2532
- state?: any;
2533
- fromRouteId?: string;
2530
+ /** Enables a {@link https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API View Transition} for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the {@link https://api.reactrouter.com/v7/functions/react_router.useViewTransitionState.html useViewTransitionState()} hook. */
2534
2531
  viewTransition?: boolean;
2535
- };
2536
- type BaseSubmissionOptions = {
2537
- formMethod?: HTMLFormMethod;
2538
- formEncType?: FormEncType;
2539
- } & ({
2540
- formData: FormData;
2541
- body?: undefined;
2542
- } | {
2543
- formData?: undefined;
2544
- body: any;
2545
- });
2546
- /**
2547
- * Options for a navigate() call for a normal (non-submission) navigation
2548
- */
2549
- type LinkNavigateOptions = BaseNavigateOptions;
2550
- /**
2551
- * Options for a navigate() call for a submission navigation
2552
- */
2553
- type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
2554
- /**
2555
- * Options to pass to navigate() for a navigation
2556
- */
2557
- type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
2558
- /**
2559
- * Options for a fetch() load
2560
- */
2561
- type LoadFetchOptions = BaseNavigateOrFetchOptions;
2562
- /**
2563
- * Options for a fetch() submission
2564
- */
2565
- type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
2566
- /**
2567
- * Options to pass to fetch()
2568
- */
2569
- type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
2570
- /**
2571
- * Potential states for state.navigation
2572
- */
2573
- type NavigationStates = {
2574
- Idle: {
2575
- state: "idle";
2576
- location: undefined;
2577
- formMethod: undefined;
2578
- formAction: undefined;
2579
- formEncType: undefined;
2580
- formData: undefined;
2581
- json: undefined;
2582
- text: undefined;
2583
- };
2584
- Loading: {
2585
- state: "loading";
2586
- location: Location;
2587
- formMethod: Submission["formMethod"] | undefined;
2588
- formAction: Submission["formAction"] | undefined;
2589
- formEncType: Submission["formEncType"] | undefined;
2590
- formData: Submission["formData"] | undefined;
2591
- json: Submission["json"] | undefined;
2592
- text: Submission["text"] | undefined;
2593
- };
2594
- Submitting: {
2595
- state: "submitting";
2596
- location: Location;
2597
- formMethod: Submission["formMethod"];
2598
- formAction: Submission["formAction"];
2599
- formEncType: Submission["formEncType"];
2600
- formData: Submission["formData"];
2601
- json: Submission["json"];
2602
- text: Submission["text"];
2603
- };
2604
- };
2605
- type Navigation = NavigationStates[keyof NavigationStates];
2606
- type RevalidationState = "idle" | "loading";
2532
+ }
2607
2533
  /**
2608
- * Potential states for fetchers
2534
+ * A Navigator is a "location changer"; it's how you get to different locations.
2535
+ *
2536
+ * Every history instance conforms to the Navigator interface, but the
2537
+ * distinction is useful primarily when it comes to the low-level `<Router>` API
2538
+ * where both the location and a navigator must be provided separately in order
2539
+ * to avoid "tearing" that may occur in a suspense-enabled app if the action
2540
+ * and/or location were to be read directly from the history instance.
2609
2541
  */
2610
- type FetcherStates<TData = any> = {
2611
- /**
2612
- * The fetcher is not calling a loader or action
2613
- *
2614
- * ```tsx
2615
- * fetcher.state === "idle"
2616
- * ```
2617
- */
2618
- Idle: {
2619
- state: "idle";
2620
- formMethod: undefined;
2621
- formAction: undefined;
2622
- formEncType: undefined;
2623
- text: undefined;
2624
- formData: undefined;
2625
- json: undefined;
2626
- /**
2627
- * If the fetcher has never been called, this will be undefined.
2628
- */
2629
- data: TData | undefined;
2630
- };
2631
- /**
2632
- * The fetcher is loading data from a {@link LoaderFunction | loader} from a
2633
- * call to {@link FetcherWithComponents.load | `fetcher.load`}.
2634
- *
2635
- * ```tsx
2636
- * // somewhere
2637
- * <button onClick={() => fetcher.load("/some/route") }>Load</button>
2638
- *
2639
- * // the state will update
2640
- * fetcher.state === "loading"
2641
- * ```
2642
- */
2643
- Loading: {
2644
- state: "loading";
2645
- formMethod: Submission["formMethod"] | undefined;
2646
- formAction: Submission["formAction"] | undefined;
2647
- formEncType: Submission["formEncType"] | undefined;
2648
- text: Submission["text"] | undefined;
2649
- formData: Submission["formData"] | undefined;
2650
- json: Submission["json"] | undefined;
2651
- data: TData | undefined;
2652
- };
2653
- /**
2654
- 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`}.
2655
-
2656
- ```tsx
2657
- // somewhere
2658
- <input
2659
- onChange={e => {
2660
- fetcher.submit(event.currentTarget.form, { method: "post" });
2661
- }}
2662
- />
2663
-
2664
- // the state will update
2665
- fetcher.state === "submitting"
2666
-
2667
- // and formData will be available
2668
- fetcher.formData
2669
- ```
2670
- */
2671
- Submitting: {
2672
- state: "submitting";
2673
- formMethod: Submission["formMethod"];
2674
- formAction: Submission["formAction"];
2675
- formEncType: Submission["formEncType"];
2676
- text: Submission["text"];
2677
- formData: Submission["formData"];
2678
- json: Submission["json"];
2679
- data: TData | undefined;
2680
- };
2681
- };
2682
- type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
2683
- interface BlockerBlocked {
2684
- state: "blocked";
2685
- reset: () => void;
2686
- proceed: () => void;
2687
- location: Location;
2542
+ interface Navigator {
2543
+ createHref: History["createHref"];
2544
+ encodeLocation?: History["encodeLocation"];
2545
+ go: History["go"];
2546
+ push(to: To, state?: any, opts?: NavigateOptions): void;
2547
+ replace(to: To, state?: any, opts?: NavigateOptions): void;
2688
2548
  }
2689
- interface BlockerUnblocked {
2690
- state: "unblocked";
2691
- reset: undefined;
2692
- proceed: undefined;
2693
- location: undefined;
2549
+ interface NavigationContextObject {
2550
+ basename: string;
2551
+ navigator: Navigator;
2552
+ static: boolean;
2553
+ future: {};
2694
2554
  }
2695
- interface BlockerProceeding {
2696
- state: "proceeding";
2697
- reset: undefined;
2698
- proceed: undefined;
2555
+ declare const NavigationContext: React.Context<NavigationContextObject>;
2556
+ interface LocationContextObject {
2699
2557
  location: Location;
2558
+ navigationType: Action;
2700
2559
  }
2701
- type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
2702
- type BlockerFunction = (args: {
2703
- currentLocation: Location;
2704
- nextLocation: Location;
2705
- historyAction: Action;
2706
- }) => boolean;
2707
- declare const IDLE_NAVIGATION: NavigationStates["Idle"];
2708
- declare const IDLE_FETCHER: FetcherStates["Idle"];
2709
- declare const IDLE_BLOCKER: BlockerUnblocked;
2710
- /**
2711
- * Create a router and listen to history POP navigations
2712
- */
2713
- declare function createRouter(init: RouterInit): Router;
2714
- interface CreateStaticHandlerOptions {
2715
- basename?: string;
2716
- mapRouteProperties?: MapRoutePropertiesFunction;
2717
- unstable_instrumentations?: Pick<unstable_ServerInstrumentation, "route">[];
2718
- future?: {};
2560
+ declare const LocationContext: React.Context<LocationContextObject>;
2561
+ interface RouteContextObject {
2562
+ outlet: React.ReactElement | null;
2563
+ matches: RouteMatch[];
2564
+ isDataRoute: boolean;
2719
2565
  }
2566
+ declare const RouteContext: React.Context<RouteContextObject>;
2720
2567
 
2721
- export { type DataStrategyFunctionArgs as $, type ActionFunctionArgs as A, type BlockerFunction as B, type RouterState as C, type DataStrategyResult as D, type ErrorBoundaryType as E, type PatchRoutesOnNavigationFunction as F, type DataRouteObject as G, type HydrationState as H, type InitialEntry as I, type StaticHandler as J, type GetScrollPositionFunction as K, type Location as L, type MiddlewareNextFunction as M, type NavigateOptions as N, type GetScrollRestorationKeyFunction as O, type Params as P, type StaticHandlerContext as Q, type RouterProviderProps as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type Fetcher as V, type NavigationStates as W, type RouterSubscriber as X, type RouterNavigateOptions as Y, type RouterFetchOptions as Z, type RevalidationState as _, type RouterInit as a, FetchersContext as a$, type DataStrategyMatch as a0, type ErrorResponse as a1, type FormEncType as a2, type FormMethod as a3, type HTMLFormMethod as a4, type LazyRouteFunction as a5, type PathParam as a6, type RedirectFunction as a7, type RouterContext as a8, type ShouldRevalidateFunctionArgs as a9, type MemoryRouterOpts as aA, type MemoryRouterProps as aB, type NavigateProps as aC, type OutletProps as aD, type PathRouteProps as aE, type RouteProps as aF, type RouterProps as aG, type RoutesProps as aH, Await as aI, MemoryRouter as aJ, Navigate as aK, Outlet as aL, Route as aM, Router$1 as aN, RouterProvider as aO, Routes as aP, createMemoryRouter as aQ, createRoutesFromChildren as aR, createRoutesFromElements as aS, renderMatches as aT, type Future as aU, createBrowserHistory as aV, invariant as aW, createRouter as aX, ErrorResponseImpl as aY, DataRouterContext as aZ, DataRouterStateContext as a_, createContext as aa, createPath as ab, parsePath as ac, type unstable_ServerInstrumentation as ad, type unstable_InstrumentRequestHandlerFunction as ae, type unstable_InstrumentRouterFunction as af, type unstable_InstrumentRouteFunction as ag, IDLE_NAVIGATION as ah, IDLE_FETCHER as ai, IDLE_BLOCKER as aj, data as ak, generatePath as al, isRouteErrorResponse as am, matchPath as an, matchRoutes as ao, redirect as ap, redirectDocument as aq, replace as ar, resolvePath as as, type Navigator as at, type PatchRoutesOnNavigationFunctionArgs as au, type RouteMatch as av, AwaitContextProvider as aw, type AwaitProps as ax, type IndexRouteProps as ay, type LayoutRouteProps as az, type unstable_ClientOnErrorFunction as b, LocationContext as b0, NavigationContext as b1, RouteContext as b2, ViewTransitionContext as b3, hydrationRouteProperties as b4, mapRouteProperties as b5, WithComponentProps as b6, withComponentProps as b7, WithHydrateFallbackProps as b8, withHydrateFallbackProps as b9, WithErrorBoundaryProps as ba, withErrorBoundaryProps as bb, type RouteManifest as bc, type History as bd, type FutureConfig as be, type CreateStaticHandlerOptions as bf, RouterContextProvider as c, DataWithResponseInit as d, type MiddlewareEnabled as e, type LoaderFunctionArgs as f, type ActionFunction as g, type LoaderFunction as h, type DataRouteMatch as i, type MiddlewareFunction as j, type Router as k, type DataStrategyFunction as l, type Blocker as m, type RelativeRoutingType as n, type ParamParseKey as o, type Path as p, type PathPattern as q, type PathMatch as r, type Navigation as s, Action as t, type unstable_ClientInstrumentation as u, type RouteObject as v, type IndexRouteObject as w, type RouteComponentType as x, type HydrateFallbackType as y, type NonIndexRouteObject as z };
2568
+ export { type DataStrategyMatch as $, type ActionFunctionArgs as A, type BlockerFunction as B, type PatchRoutesOnNavigationFunction as C, type DataStrategyResult as D, type ErrorBoundaryType as E, type DataRouteObject as F, type StaticHandler as G, type HydrationState as H, type InitialEntry as I, type GetScrollPositionFunction as J, type GetScrollRestorationKeyFunction as K, type Location as L, type MiddlewareNextFunction as M, type NavigateOptions as N, type StaticHandlerContext as O, type Params as P, type Fetcher as Q, type RouterProviderProps as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type NavigationStates as V, type RouterSubscriber as W, type RouterNavigateOptions as X, type RouterFetchOptions as Y, type RevalidationState as Z, type DataStrategyFunctionArgs as _, type RouterInit as a, hydrationRouteProperties as a$, type ErrorResponse as a0, type FormEncType as a1, type FormMethod as a2, type HTMLFormMethod as a3, type LazyRouteFunction as a4, type PathParam as a5, type RedirectFunction as a6, type RouterContext as a7, type ShouldRevalidateFunctionArgs as a8, createContext as a9, type RouteProps as aA, type RouterProps as aB, type RoutesProps as aC, Await as aD, MemoryRouter as aE, Navigate as aF, Outlet as aG, Route as aH, Router as aI, RouterProvider as aJ, Routes as aK, createMemoryRouter as aL, createRoutesFromChildren as aM, createRoutesFromElements as aN, renderMatches as aO, type Future as aP, createBrowserHistory as aQ, invariant as aR, createRouter as aS, ErrorResponseImpl as aT, DataRouterContext as aU, DataRouterStateContext as aV, FetchersContext as aW, LocationContext as aX, NavigationContext as aY, RouteContext as aZ, ViewTransitionContext as a_, createPath as aa, parsePath as ab, IDLE_NAVIGATION as ac, IDLE_FETCHER as ad, IDLE_BLOCKER as ae, data as af, generatePath as ag, isRouteErrorResponse as ah, matchPath as ai, matchRoutes as aj, redirect as ak, redirectDocument as al, replace as am, resolvePath as an, type Navigator as ao, type PatchRoutesOnNavigationFunctionArgs as ap, type RouteMatch as aq, AwaitContextProvider as ar, type AwaitProps as as, type IndexRouteProps as at, type LayoutRouteProps as au, type MemoryRouterOpts as av, type MemoryRouterProps as aw, type NavigateProps as ax, type OutletProps as ay, type PathRouteProps as az, type LoaderFunctionArgs as b, mapRouteProperties as b0, WithComponentProps as b1, withComponentProps as b2, WithHydrateFallbackProps as b3, withHydrateFallbackProps as b4, WithErrorBoundaryProps as b5, withErrorBoundaryProps as b6, type RouteManifest as b7, type History as b8, type FutureConfig as b9, type CreateStaticHandlerOptions as ba, type ActionFunction as c, type LoaderFunction as d, type DataRouteMatch as e, type MiddlewareFunction as f, RouterContextProvider as g, DataWithResponseInit as h, type MiddlewareEnabled as i, type Router$1 as j, type DataStrategyFunction as k, type Blocker as l, type RelativeRoutingType as m, type ParamParseKey as n, type Path as o, type PathPattern as p, type PathMatch as q, type Navigation as r, Action as s, type RouteObject as t, type unstable_ClientOnErrorFunction as u, type IndexRouteObject as v, type RouteComponentType as w, type HydrateFallbackType as x, type NonIndexRouteObject as y, type RouterState as z };