react-router 0.0.0-experimental-c19b79d → 0.0.0-experimental-e0b6ce9

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