react-router 7.9.4 → 7.9.6

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