react-router 0.0.0-experimental-e613d4238 → 0.0.0-experimental-4e44d47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/{chunk-YJ6T7YSE.js → chunk-7B7CUJYE.js} +345 -66
- package/dist/development/{chunk-XXC4LMW2.js → chunk-MTLWRICG.js} +164 -161
- package/dist/development/{chunk-2YVPYFDJ.mjs → chunk-PSQFTIPQ.mjs} +67 -51
- package/dist/development/{chunk-5P3HEZQU.mjs → chunk-XVVWTPHF.mjs} +307 -25
- package/dist/development/dom-export.d.mts +59 -4
- package/dist/development/dom-export.d.ts +59 -3
- package/dist/development/dom-export.js +8 -5
- package/dist/development/dom-export.mjs +8 -5
- package/dist/development/{index-react-server-client-DKvU8YRr.d.ts → index-react-server-client-83aVZHgI.d.ts} +198 -134
- package/dist/{production/index-react-server-client-2EDmGlsZ.d.mts → development/index-react-server-client-BDG19ZQl.d.mts} +140 -77
- package/dist/development/index-react-server-client.d.mts +3 -3
- package/dist/development/index-react-server-client.d.ts +3 -2
- package/dist/development/index-react-server-client.js +4 -4
- package/dist/development/index-react-server-client.mjs +2 -2
- package/dist/development/index-react-server.d.mts +106 -1
- package/dist/development/index-react-server.d.ts +106 -1
- package/dist/development/index-react-server.js +181 -8
- package/dist/development/index-react-server.mjs +181 -8
- package/dist/development/index.d.mts +13 -18
- package/dist/development/index.d.ts +13 -16
- package/dist/development/index.js +161 -147
- package/dist/development/index.mjs +3 -5
- package/dist/development/instrumentation-XYmrzhe3.d.ts +1138 -0
- package/dist/development/lib/types/internal.d.mts +3 -3
- package/dist/development/lib/types/internal.d.ts +3 -2
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/{register-BrVEYTED.d.mts → register-DiOIlEq5.d.mts} +1 -7
- package/dist/{production/register-BrVEYTED.d.mts → development/register-DiOIlEq5.d.ts} +1 -7
- package/dist/development/{routeModules-BmVo7q9e.d.ts → routeModules-Bu1JamQV.d.ts} +73 -1046
- package/dist/development/{route-data-CDwqkzPE.d.mts → routeModules-CtCOLGtG.d.mts} +157 -147
- package/dist/development/{context-BqL5Eckq.d.mts → router-2BoB34m1.d.mts} +1403 -1250
- package/dist/production/{chunk-VNGQS422.mjs → chunk-GSSVRQ6M.mjs} +307 -25
- package/dist/production/{chunk-5MHETEIL.mjs → chunk-IZVJSKMU.mjs} +67 -51
- package/dist/production/{chunk-QBUHFRYZ.js → chunk-OXRQQZPR.js} +345 -66
- package/dist/production/{chunk-E4G6PZCJ.js → chunk-UNIYMJFU.js} +164 -161
- package/dist/production/dom-export.d.mts +59 -4
- package/dist/production/dom-export.d.ts +59 -3
- package/dist/production/dom-export.js +8 -5
- package/dist/production/dom-export.mjs +8 -5
- package/dist/{development/index-react-server-client-2EDmGlsZ.d.mts → production/index-react-server-client-83aVZHgI.d.ts} +140 -77
- package/dist/production/{index-react-server-client-DKvU8YRr.d.ts → index-react-server-client-BDG19ZQl.d.mts} +198 -134
- package/dist/production/index-react-server-client.d.mts +3 -3
- package/dist/production/index-react-server-client.d.ts +3 -2
- package/dist/production/index-react-server-client.js +4 -4
- package/dist/production/index-react-server-client.mjs +2 -2
- package/dist/production/index-react-server.d.mts +106 -1
- package/dist/production/index-react-server.d.ts +106 -1
- package/dist/production/index-react-server.js +181 -8
- package/dist/production/index-react-server.mjs +181 -8
- package/dist/production/index.d.mts +13 -18
- package/dist/production/index.d.ts +13 -16
- package/dist/production/index.js +161 -147
- package/dist/production/index.mjs +3 -5
- package/dist/production/instrumentation-XYmrzhe3.d.ts +1138 -0
- package/dist/production/lib/types/internal.d.mts +3 -3
- package/dist/production/lib/types/internal.d.ts +3 -2
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/{development/register-D8NQoPsO.d.ts → production/register-DiOIlEq5.d.mts} +1 -7
- package/dist/production/{register-D8NQoPsO.d.ts → register-DiOIlEq5.d.ts} +1 -7
- package/dist/production/{routeModules-BmVo7q9e.d.ts → routeModules-Bu1JamQV.d.ts} +73 -1046
- package/dist/production/{route-data-CDwqkzPE.d.mts → routeModules-CtCOLGtG.d.mts} +157 -147
- package/dist/production/{context-BqL5Eckq.d.mts → router-2BoB34m1.d.mts} +1403 -1250
- 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
|
+
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:
|
|
622
|
+
(route: AgnosticDataRouteObject): {
|
|
618
623
|
hasErrorBoundary: boolean;
|
|
619
624
|
} & Record<string, any>;
|
|
620
625
|
}
|
|
@@ -1039,1530 +1044,1678 @@ 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
|
-
*
|
|
1052
|
+
* @category Data Routers
|
|
1044
1053
|
*/
|
|
1045
|
-
interface
|
|
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
|
-
*
|
|
1062
|
-
* PRIVATE - DO NOT USE
|
|
1063
|
-
*
|
|
1064
|
-
* Return the current state of the router
|
|
1056
|
+
* Basename path for the application.
|
|
1065
1057
|
*/
|
|
1066
|
-
|
|
1058
|
+
basename?: string;
|
|
1067
1059
|
/**
|
|
1068
|
-
* @
|
|
1069
|
-
*
|
|
1070
|
-
*
|
|
1071
|
-
*
|
|
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
|
-
|
|
1066
|
+
getContext?: RouterInit["getContext"];
|
|
1074
1067
|
/**
|
|
1075
|
-
*
|
|
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
|
-
|
|
1070
|
+
future?: Partial<FutureConfig>;
|
|
1081
1071
|
/**
|
|
1082
|
-
*
|
|
1083
|
-
*
|
|
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
|
-
|
|
1075
|
+
hydrationData?: HydrationState;
|
|
1090
1076
|
/**
|
|
1091
|
-
*
|
|
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
|
-
|
|
1079
|
+
initialEntries?: InitialEntry[];
|
|
1099
1080
|
/**
|
|
1100
|
-
*
|
|
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
|
-
|
|
1083
|
+
initialIndex?: number;
|
|
1111
1084
|
/**
|
|
1112
|
-
*
|
|
1113
|
-
*
|
|
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
|
-
*
|
|
1116
|
-
*
|
|
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
|
-
|
|
1135
|
+
unstable_instrumentations?: unstable_ClientInstrumentation[];
|
|
1119
1136
|
/**
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
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
|
-
|
|
1140
|
+
dataStrategy?: DataStrategyFunction;
|
|
1125
1141
|
/**
|
|
1126
|
-
*
|
|
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
|
-
|
|
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
|
-
* @
|
|
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
|
-
|
|
1182
|
+
router: Router;
|
|
1144
1183
|
/**
|
|
1145
|
-
*
|
|
1146
|
-
*
|
|
1184
|
+
* The [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
|
|
1185
|
+
* implementation to use for flushing updates.
|
|
1147
1186
|
*
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
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
|
-
|
|
1192
|
+
flushSync?: (fn: () => unknown) => undefined;
|
|
1152
1193
|
/**
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
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
|
-
*
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
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
|
-
*
|
|
1166
|
-
*
|
|
1203
|
+
* ```tsx
|
|
1204
|
+
* <RouterProvider unstable_onError=(error, errorInfo) => {
|
|
1205
|
+
* console.error(error, errorInfo);
|
|
1206
|
+
* reportToErrorService(error, errorInfo);
|
|
1207
|
+
* }} />
|
|
1208
|
+
* ```
|
|
1167
1209
|
*/
|
|
1168
|
-
|
|
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
|
-
*
|
|
1171
|
-
* PRIVATE - DO NOT USE
|
|
1172
|
-
*
|
|
1173
|
-
* Reset the fetcher for a given key
|
|
1174
|
-
* @param key
|
|
1249
|
+
* Application basename
|
|
1175
1250
|
*/
|
|
1176
|
-
|
|
1177
|
-
reason?: unknown;
|
|
1178
|
-
}): void;
|
|
1251
|
+
basename?: string;
|
|
1179
1252
|
/**
|
|
1180
|
-
* @
|
|
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
|
-
|
|
1255
|
+
children?: React.ReactNode;
|
|
1187
1256
|
/**
|
|
1188
|
-
*
|
|
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
|
-
|
|
1259
|
+
initialEntries?: InitialEntry[];
|
|
1194
1260
|
/**
|
|
1195
|
-
*
|
|
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
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
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
|
-
|
|
1287
|
+
to: To;
|
|
1211
1288
|
/**
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
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
|
-
|
|
1292
|
+
replace?: boolean;
|
|
1224
1293
|
/**
|
|
1225
|
-
* @
|
|
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
|
-
|
|
1296
|
+
state?: any;
|
|
1232
1297
|
/**
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
1241
|
-
*
|
|
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
|
-
*
|
|
1332
|
+
* ```tsx
|
|
1333
|
+
* <Outlet context={myContextValue} />
|
|
1334
|
+
* ```
|
|
1335
|
+
*
|
|
1336
|
+
* Access the context with {@link useOutletContext}.
|
|
1244
1337
|
*/
|
|
1245
|
-
|
|
1338
|
+
context?: unknown;
|
|
1246
1339
|
}
|
|
1247
1340
|
/**
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
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
|
-
|
|
1362
|
+
declare function Outlet(props: OutletProps): React.ReactElement | null;
|
|
1363
|
+
/**
|
|
1364
|
+
* @category Types
|
|
1365
|
+
*/
|
|
1366
|
+
interface PathRouteProps {
|
|
1252
1367
|
/**
|
|
1253
|
-
*
|
|
1368
|
+
* Whether the path should be case-sensitive. Defaults to `false`.
|
|
1254
1369
|
*/
|
|
1255
|
-
|
|
1370
|
+
caseSensitive?: NonIndexRouteObject["caseSensitive"];
|
|
1256
1371
|
/**
|
|
1257
|
-
* The
|
|
1372
|
+
* The path pattern to match. If unspecified or empty, then this becomes a
|
|
1373
|
+
* layout route.
|
|
1258
1374
|
*/
|
|
1259
|
-
|
|
1375
|
+
path?: NonIndexRouteObject["path"];
|
|
1260
1376
|
/**
|
|
1261
|
-
* The
|
|
1377
|
+
* The unique identifier for this route (for use with {@link DataRouter}s)
|
|
1262
1378
|
*/
|
|
1263
|
-
|
|
1379
|
+
id?: NonIndexRouteObject["id"];
|
|
1264
1380
|
/**
|
|
1265
|
-
*
|
|
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
|
-
|
|
1385
|
+
lazy?: LazyRouteFunction<NonIndexRouteObject>;
|
|
1268
1386
|
/**
|
|
1269
|
-
*
|
|
1270
|
-
*
|
|
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
|
-
|
|
1390
|
+
middleware?: NonIndexRouteObject["middleware"];
|
|
1275
1391
|
/**
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1392
|
+
* The route loader.
|
|
1393
|
+
* See [`loader`](../../start/data/route-object#loader).
|
|
1278
1394
|
*/
|
|
1279
|
-
|
|
1395
|
+
loader?: NonIndexRouteObject["loader"];
|
|
1280
1396
|
/**
|
|
1281
|
-
*
|
|
1397
|
+
* The route action.
|
|
1398
|
+
* See [`action`](../../start/data/route-object#action).
|
|
1282
1399
|
*/
|
|
1283
|
-
|
|
1400
|
+
action?: NonIndexRouteObject["action"];
|
|
1401
|
+
hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
|
|
1284
1402
|
/**
|
|
1285
|
-
*
|
|
1403
|
+
* The route shouldRevalidate function.
|
|
1404
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
|
|
1286
1405
|
*/
|
|
1287
|
-
|
|
1406
|
+
shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
|
|
1288
1407
|
/**
|
|
1289
|
-
*
|
|
1408
|
+
* The route handle.
|
|
1290
1409
|
*/
|
|
1291
|
-
|
|
1410
|
+
handle?: NonIndexRouteObject["handle"];
|
|
1292
1411
|
/**
|
|
1293
|
-
*
|
|
1412
|
+
* Whether this is an index route.
|
|
1294
1413
|
*/
|
|
1295
|
-
|
|
1414
|
+
index?: false;
|
|
1296
1415
|
/**
|
|
1297
|
-
*
|
|
1416
|
+
* Child Route components
|
|
1298
1417
|
*/
|
|
1299
|
-
|
|
1418
|
+
children?: React.ReactNode;
|
|
1300
1419
|
/**
|
|
1301
|
-
*
|
|
1420
|
+
* The React element to render when this Route matches.
|
|
1421
|
+
* Mutually exclusive with `Component`.
|
|
1302
1422
|
*/
|
|
1303
|
-
|
|
1423
|
+
element?: React.ReactNode | null;
|
|
1304
1424
|
/**
|
|
1305
|
-
*
|
|
1425
|
+
* The React element to render while this router is loading data.
|
|
1426
|
+
* Mutually exclusive with `HydrateFallback`.
|
|
1306
1427
|
*/
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
/**
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
/**
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
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
|
-
*
|
|
1451
|
+
* @category Types
|
|
1336
1452
|
*/
|
|
1337
|
-
interface
|
|
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
|
-
*
|
|
1456
|
+
* @category Types
|
|
1351
1457
|
*/
|
|
1352
|
-
interface
|
|
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
|
-
*
|
|
1495
|
-
*
|
|
1496
|
-
* ```tsx
|
|
1497
|
-
* fetcher.state === "idle"
|
|
1498
|
-
* ```
|
|
1460
|
+
* Whether the path should be case-sensitive. Defaults to `false`.
|
|
1499
1461
|
*/
|
|
1500
|
-
|
|
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
|
|
1515
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
1477
|
+
lazy?: LazyRouteFunction<IndexRouteObject>;
|
|
1614
1478
|
/**
|
|
1615
|
-
*
|
|
1616
|
-
*
|
|
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
|
-
|
|
1482
|
+
middleware?: IndexRouteObject["middleware"];
|
|
1622
1483
|
/**
|
|
1623
|
-
*
|
|
1484
|
+
* The route loader.
|
|
1485
|
+
* See [`loader`](../../start/data/route-object#loader).
|
|
1624
1486
|
*/
|
|
1625
|
-
|
|
1487
|
+
loader?: IndexRouteObject["loader"];
|
|
1626
1488
|
/**
|
|
1627
|
-
*
|
|
1628
|
-
* data
|
|
1489
|
+
* The route action.
|
|
1490
|
+
* See [`action`](../../start/data/route-object#action).
|
|
1629
1491
|
*/
|
|
1630
|
-
|
|
1492
|
+
action?: IndexRouteObject["action"];
|
|
1493
|
+
hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
|
|
1631
1494
|
/**
|
|
1632
|
-
*
|
|
1495
|
+
* The route shouldRevalidate function.
|
|
1496
|
+
* See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
|
|
1633
1497
|
*/
|
|
1634
|
-
|
|
1498
|
+
shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
|
|
1635
1499
|
/**
|
|
1636
|
-
*
|
|
1500
|
+
* The route handle.
|
|
1637
1501
|
*/
|
|
1638
|
-
|
|
1502
|
+
handle?: IndexRouteObject["handle"];
|
|
1639
1503
|
/**
|
|
1640
|
-
*
|
|
1641
|
-
* Only intended for advanced usage.
|
|
1504
|
+
* Whether this is an index route.
|
|
1642
1505
|
*/
|
|
1643
|
-
|
|
1506
|
+
index: true;
|
|
1644
1507
|
/**
|
|
1645
|
-
*
|
|
1508
|
+
* Child Route components
|
|
1646
1509
|
*/
|
|
1647
|
-
|
|
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
|
|
1512
|
+
* The React element to render when this Route matches.
|
|
1513
|
+
* Mutually exclusive with `Component`.
|
|
1683
1514
|
*/
|
|
1684
|
-
|
|
1515
|
+
element?: React.ReactNode | null;
|
|
1685
1516
|
/**
|
|
1686
|
-
* The
|
|
1687
|
-
*
|
|
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
|
-
|
|
1520
|
+
hydrateFallbackElement?: React.ReactNode | null;
|
|
1695
1521
|
/**
|
|
1696
|
-
*
|
|
1697
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
1716
|
-
*
|
|
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
|
-
*
|
|
1719
|
-
*
|
|
1720
|
-
*
|
|
1721
|
-
*
|
|
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
|
-
*
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
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
|
-
*
|
|
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
|
|
1738
|
-
* @mode data
|
|
1579
|
+
* @category Components
|
|
1739
1580
|
* @param props Props
|
|
1740
|
-
* @param {
|
|
1741
|
-
* @param {
|
|
1742
|
-
* @param {
|
|
1743
|
-
* @
|
|
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
|
|
1599
|
+
declare function Route(props: RouteProps): React.ReactElement | null;
|
|
1746
1600
|
/**
|
|
1747
1601
|
* @category Types
|
|
1748
1602
|
*/
|
|
1749
|
-
interface
|
|
1603
|
+
interface RouterProps {
|
|
1750
1604
|
/**
|
|
1751
|
-
*
|
|
1605
|
+
* The base path for the application. This is prepended to all locations
|
|
1752
1606
|
*/
|
|
1753
1607
|
basename?: string;
|
|
1754
1608
|
/**
|
|
1755
|
-
* Nested {@link Route} elements describing the route tree
|
|
1609
|
+
* Nested {@link Route} elements describing the route tree
|
|
1610
|
+
*/
|
|
1611
|
+
children?: React.ReactNode;
|
|
1612
|
+
/**
|
|
1613
|
+
* The location to match against. Defaults to the current location.
|
|
1614
|
+
* This can be a string or a {@link Location} object.
|
|
1615
|
+
*/
|
|
1616
|
+
location: Partial<Location> | string;
|
|
1617
|
+
/**
|
|
1618
|
+
* The type of navigation that triggered this `location` change.
|
|
1619
|
+
* Defaults to {@link NavigationType.Pop}.
|
|
1756
1620
|
*/
|
|
1757
|
-
|
|
1621
|
+
navigationType?: Action;
|
|
1758
1622
|
/**
|
|
1759
|
-
*
|
|
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
|
-
|
|
1626
|
+
navigator: Navigator;
|
|
1762
1627
|
/**
|
|
1763
|
-
*
|
|
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
|
-
|
|
1631
|
+
static?: boolean;
|
|
1766
1632
|
}
|
|
1767
1633
|
/**
|
|
1768
|
-
*
|
|
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 {
|
|
1775
|
-
* @param {
|
|
1776
|
-
* @param {
|
|
1777
|
-
* @param {
|
|
1778
|
-
* @
|
|
1779
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
1659
|
+
* Nested {@link Route} elements
|
|
1797
1660
|
*/
|
|
1798
|
-
|
|
1661
|
+
children?: React.ReactNode;
|
|
1799
1662
|
/**
|
|
1800
|
-
*
|
|
1801
|
-
* See {@link RelativeRoutingType}.
|
|
1663
|
+
* The {@link Location} to match against. Defaults to the current location.
|
|
1802
1664
|
*/
|
|
1803
|
-
|
|
1665
|
+
location?: Partial<Location> | string;
|
|
1804
1666
|
}
|
|
1805
1667
|
/**
|
|
1806
|
-
*
|
|
1807
|
-
*
|
|
1808
|
-
*
|
|
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
|
-
*
|
|
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 {
|
|
1819
|
-
* @param {
|
|
1820
|
-
* @
|
|
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
|
|
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
|
|
1696
|
+
interface AwaitProps<Resolve> {
|
|
1830
1697
|
/**
|
|
1831
|
-
*
|
|
1832
|
-
*
|
|
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
|
-
* <
|
|
1726
|
+
* <Await
|
|
1727
|
+
* errorElement={<div>Oops</div>}
|
|
1728
|
+
* resolve={reviewsPromise}
|
|
1729
|
+
* >
|
|
1730
|
+
* <Reviews />
|
|
1731
|
+
* </Await>
|
|
1836
1732
|
* ```
|
|
1837
1733
|
*
|
|
1838
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
1844
|
-
*
|
|
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)
|
|
1845
1802
|
*
|
|
1846
1803
|
* @example
|
|
1847
|
-
* import {
|
|
1804
|
+
* import { Await, useLoaderData } from "react-router";
|
|
1848
1805
|
*
|
|
1849
|
-
* export
|
|
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();
|
|
1850
1816
|
* return (
|
|
1851
1817
|
* <div>
|
|
1852
|
-
* <h1>
|
|
1853
|
-
* <
|
|
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>
|
|
1854
1831
|
* </div>
|
|
1855
1832
|
* );
|
|
1856
1833
|
* }
|
|
1857
1834
|
*
|
|
1858
1835
|
* @public
|
|
1859
|
-
* @category Components
|
|
1860
|
-
* @
|
|
1861
|
-
* @
|
|
1862
|
-
* @
|
|
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
|
+
* );
|
|
1869
|
+
*
|
|
1870
|
+
* const router = createBrowserRouter(routes);
|
|
1871
|
+
*
|
|
1872
|
+
* function App() {
|
|
1873
|
+
* return <RouterProvider router={router} />;
|
|
1874
|
+
* }
|
|
1875
|
+
*
|
|
1876
|
+
* @name createRoutesFromElements
|
|
1877
|
+
* @public
|
|
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
|
|
1886
|
+
declare const createRoutesFromElements: typeof createRoutesFromChildren;
|
|
1865
1887
|
/**
|
|
1866
|
-
* @
|
|
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
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
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: {};
|
|
2052
|
+
}
|
|
2053
|
+
declare const NavigationContext: React.Context<NavigationContextObject>;
|
|
2054
|
+
interface LocationContextObject {
|
|
2055
|
+
location: Location;
|
|
2056
|
+
navigationType: Action;
|
|
1951
2057
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
2058
|
+
declare const LocationContext: React.Context<LocationContextObject>;
|
|
2059
|
+
interface RouteContextObject {
|
|
2060
|
+
outlet: React.ReactElement | null;
|
|
2061
|
+
matches: RouteMatch[];
|
|
2062
|
+
isDataRoute: boolean;
|
|
2063
|
+
}
|
|
2064
|
+
declare const RouteContext: React.Context<RouteContextObject>;
|
|
2065
|
+
|
|
2066
|
+
type unstable_ServerInstrumentation = {
|
|
2067
|
+
handler?: unstable_InstrumentRequestHandlerFunction;
|
|
2068
|
+
route?: unstable_InstrumentRouteFunction;
|
|
2069
|
+
};
|
|
2070
|
+
type unstable_ClientInstrumentation = {
|
|
2071
|
+
router?: unstable_InstrumentRouterFunction;
|
|
2072
|
+
route?: unstable_InstrumentRouteFunction;
|
|
2073
|
+
};
|
|
2074
|
+
type unstable_InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
|
|
2075
|
+
type unstable_InstrumentRouterFunction = (router: InstrumentableRouter) => void;
|
|
2076
|
+
type unstable_InstrumentRouteFunction = (route: InstrumentableRoute) => void;
|
|
2077
|
+
interface GenericInstrumentFunction {
|
|
2078
|
+
(handler: () => Promise<void>, info: unknown): Promise<void>;
|
|
2079
|
+
}
|
|
2080
|
+
type InstrumentableRoute = {
|
|
2081
|
+
id: string;
|
|
2082
|
+
index: boolean | undefined;
|
|
2083
|
+
path: string | undefined;
|
|
2084
|
+
instrument(instrumentations: RouteInstrumentations): void;
|
|
2085
|
+
};
|
|
2086
|
+
type RouteInstrumentations = {
|
|
2087
|
+
lazy?: InstrumentLazyFunction;
|
|
2088
|
+
"lazy.loader"?: InstrumentLazyFunction;
|
|
2089
|
+
"lazy.action"?: InstrumentLazyFunction;
|
|
2090
|
+
"lazy.middleware"?: InstrumentLazyFunction;
|
|
2091
|
+
middleware?: InstrumentRouteHandlerFunction;
|
|
2092
|
+
loader?: InstrumentRouteHandlerFunction;
|
|
2093
|
+
action?: InstrumentRouteHandlerFunction;
|
|
2094
|
+
};
|
|
2095
|
+
type RouteHandlerInstrumentationInfo = Readonly<{
|
|
2096
|
+
request: {
|
|
2097
|
+
method: string;
|
|
2098
|
+
url: string;
|
|
2099
|
+
headers: Pick<Headers, "get">;
|
|
2100
|
+
};
|
|
2101
|
+
params: LoaderFunctionArgs["params"];
|
|
2102
|
+
pattern: string;
|
|
2103
|
+
context: Pick<RouterContextProvider, "get">;
|
|
2104
|
+
}>;
|
|
2105
|
+
interface InstrumentLazyFunction extends GenericInstrumentFunction {
|
|
2106
|
+
(handler: () => Promise<void>): Promise<void>;
|
|
2107
|
+
}
|
|
2108
|
+
interface InstrumentRouteHandlerFunction extends GenericInstrumentFunction {
|
|
2109
|
+
(handler: () => Promise<void>, info: RouteHandlerInstrumentationInfo): Promise<void>;
|
|
2110
|
+
}
|
|
2111
|
+
type InstrumentableRouter = {
|
|
2112
|
+
instrument(instrumentations: RouterInstrumentations): void;
|
|
2113
|
+
};
|
|
2114
|
+
type RouterInstrumentations = {
|
|
2115
|
+
navigate?: InstrumentNavigateFunction;
|
|
2116
|
+
fetch?: InstrumentFetchFunction;
|
|
2117
|
+
};
|
|
2118
|
+
type RouterNavigationInstrumentationInfo = Readonly<{
|
|
2119
|
+
to: string | number;
|
|
2120
|
+
currentUrl: string;
|
|
2121
|
+
formMethod?: HTMLFormMethod;
|
|
2122
|
+
formEncType?: FormEncType;
|
|
2123
|
+
formData?: FormData;
|
|
2124
|
+
body?: any;
|
|
2125
|
+
}>;
|
|
2126
|
+
type RouterFetchInstrumentationInfo = Readonly<{
|
|
2127
|
+
href: string;
|
|
2128
|
+
currentUrl: string;
|
|
2129
|
+
fetcherKey: string;
|
|
2130
|
+
formMethod?: HTMLFormMethod;
|
|
2131
|
+
formEncType?: FormEncType;
|
|
2132
|
+
formData?: FormData;
|
|
2133
|
+
body?: any;
|
|
2134
|
+
}>;
|
|
2135
|
+
interface InstrumentNavigateFunction extends GenericInstrumentFunction {
|
|
2136
|
+
(handler: () => Promise<void>, info: RouterNavigationInstrumentationInfo): MaybePromise<void>;
|
|
2137
|
+
}
|
|
2138
|
+
interface InstrumentFetchFunction extends GenericInstrumentFunction {
|
|
2139
|
+
(handler: () => Promise<void>, info: RouterFetchInstrumentationInfo): MaybePromise<void>;
|
|
2140
|
+
}
|
|
2141
|
+
type InstrumentableRequestHandler = {
|
|
2142
|
+
instrument(instrumentations: RequestHandlerInstrumentations): void;
|
|
2143
|
+
};
|
|
2144
|
+
type RequestHandlerInstrumentations = {
|
|
2145
|
+
request?: InstrumentRequestHandlerFunction;
|
|
2146
|
+
};
|
|
2147
|
+
type RequestHandlerInstrumentationInfo = Readonly<{
|
|
2148
|
+
request: {
|
|
2149
|
+
method: string;
|
|
2150
|
+
url: string;
|
|
2151
|
+
headers: Pick<Headers, "get">;
|
|
2152
|
+
};
|
|
2153
|
+
context: Pick<RouterContextProvider, "get">;
|
|
2154
|
+
}>;
|
|
2155
|
+
interface InstrumentRequestHandlerFunction extends GenericInstrumentFunction {
|
|
2156
|
+
(handler: () => Promise<void>, info: RequestHandlerInstrumentationInfo): MaybePromise<void>;
|
|
1956
2157
|
}
|
|
2158
|
+
|
|
1957
2159
|
/**
|
|
1958
|
-
*
|
|
2160
|
+
* A Router instance manages all navigation and data loading/mutations
|
|
1959
2161
|
*/
|
|
1960
|
-
interface
|
|
2162
|
+
interface Router {
|
|
1961
2163
|
/**
|
|
1962
|
-
*
|
|
2164
|
+
* @private
|
|
2165
|
+
* PRIVATE - DO NOT USE
|
|
2166
|
+
*
|
|
2167
|
+
* Return the basename for the router
|
|
1963
2168
|
*/
|
|
1964
|
-
|
|
2169
|
+
get basename(): RouterInit["basename"];
|
|
1965
2170
|
/**
|
|
1966
|
-
*
|
|
1967
|
-
*
|
|
2171
|
+
* @private
|
|
2172
|
+
* PRIVATE - DO NOT USE
|
|
2173
|
+
*
|
|
2174
|
+
* Return the future config for the router
|
|
1968
2175
|
*/
|
|
1969
|
-
|
|
2176
|
+
get future(): FutureConfig;
|
|
1970
2177
|
/**
|
|
1971
|
-
*
|
|
2178
|
+
* @private
|
|
2179
|
+
* PRIVATE - DO NOT USE
|
|
2180
|
+
*
|
|
2181
|
+
* Return the current state of the router
|
|
1972
2182
|
*/
|
|
1973
|
-
|
|
2183
|
+
get state(): RouterState;
|
|
1974
2184
|
/**
|
|
1975
|
-
*
|
|
1976
|
-
*
|
|
1977
|
-
*
|
|
2185
|
+
* @private
|
|
2186
|
+
* PRIVATE - DO NOT USE
|
|
2187
|
+
*
|
|
2188
|
+
* Return the routes for this router instance
|
|
1978
2189
|
*/
|
|
1979
|
-
|
|
2190
|
+
get routes(): AgnosticDataRouteObject[];
|
|
1980
2191
|
/**
|
|
1981
|
-
*
|
|
1982
|
-
*
|
|
2192
|
+
* @private
|
|
2193
|
+
* PRIVATE - DO NOT USE
|
|
2194
|
+
*
|
|
2195
|
+
* Return the window associated with the router
|
|
1983
2196
|
*/
|
|
1984
|
-
|
|
2197
|
+
get window(): RouterInit["window"];
|
|
1985
2198
|
/**
|
|
1986
|
-
*
|
|
1987
|
-
*
|
|
2199
|
+
* @private
|
|
2200
|
+
* PRIVATE - DO NOT USE
|
|
2201
|
+
*
|
|
2202
|
+
* Initialize the router, including adding history listeners and kicking off
|
|
2203
|
+
* initial data fetches. Returns a function to cleanup listeners and abort
|
|
2204
|
+
* any in-progress loads
|
|
1988
2205
|
*/
|
|
1989
|
-
|
|
2206
|
+
initialize(): Router;
|
|
1990
2207
|
/**
|
|
1991
|
-
*
|
|
1992
|
-
*
|
|
2208
|
+
* @private
|
|
2209
|
+
* PRIVATE - DO NOT USE
|
|
2210
|
+
*
|
|
2211
|
+
* Subscribe to router.state updates
|
|
2212
|
+
*
|
|
2213
|
+
* @param fn function to call with the new state
|
|
1993
2214
|
*/
|
|
1994
|
-
|
|
1995
|
-
hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
|
|
2215
|
+
subscribe(fn: RouterSubscriber): () => void;
|
|
1996
2216
|
/**
|
|
1997
|
-
*
|
|
1998
|
-
*
|
|
2217
|
+
* @private
|
|
2218
|
+
* PRIVATE - DO NOT USE
|
|
2219
|
+
*
|
|
2220
|
+
* Enable scroll restoration behavior in the router
|
|
2221
|
+
*
|
|
2222
|
+
* @param savedScrollPositions Object that will manage positions, in case
|
|
2223
|
+
* it's being restored from sessionStorage
|
|
2224
|
+
* @param getScrollPosition Function to get the active Y scroll position
|
|
2225
|
+
* @param getKey Function to get the key to use for restoration
|
|
1999
2226
|
*/
|
|
2000
|
-
|
|
2227
|
+
enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
|
|
2001
2228
|
/**
|
|
2002
|
-
*
|
|
2229
|
+
* @private
|
|
2230
|
+
* PRIVATE - DO NOT USE
|
|
2231
|
+
*
|
|
2232
|
+
* Navigate forward/backward in the history stack
|
|
2233
|
+
* @param to Delta to move in the history stack
|
|
2003
2234
|
*/
|
|
2004
|
-
|
|
2235
|
+
navigate(to: number): Promise<void>;
|
|
2005
2236
|
/**
|
|
2006
|
-
*
|
|
2237
|
+
* Navigate to the given path
|
|
2238
|
+
* @param to Path to navigate to
|
|
2239
|
+
* @param opts Navigation options (method, submission, etc.)
|
|
2007
2240
|
*/
|
|
2008
|
-
|
|
2241
|
+
navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
|
|
2009
2242
|
/**
|
|
2010
|
-
*
|
|
2243
|
+
* @private
|
|
2244
|
+
* PRIVATE - DO NOT USE
|
|
2245
|
+
*
|
|
2246
|
+
* Trigger a fetcher load/submission
|
|
2247
|
+
*
|
|
2248
|
+
* @param key Fetcher key
|
|
2249
|
+
* @param routeId Route that owns the fetcher
|
|
2250
|
+
* @param href href to fetch
|
|
2251
|
+
* @param opts Fetcher options, (method, submission, etc.)
|
|
2011
2252
|
*/
|
|
2012
|
-
|
|
2253
|
+
fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
|
|
2013
2254
|
/**
|
|
2014
|
-
*
|
|
2015
|
-
*
|
|
2255
|
+
* @private
|
|
2256
|
+
* PRIVATE - DO NOT USE
|
|
2257
|
+
*
|
|
2258
|
+
* Trigger a revalidation of all current route loaders and fetcher loads
|
|
2016
2259
|
*/
|
|
2017
|
-
|
|
2260
|
+
revalidate(): Promise<void>;
|
|
2018
2261
|
/**
|
|
2019
|
-
*
|
|
2020
|
-
*
|
|
2262
|
+
* @private
|
|
2263
|
+
* PRIVATE - DO NOT USE
|
|
2264
|
+
*
|
|
2265
|
+
* Utility function to create an href for the given location
|
|
2266
|
+
* @param location
|
|
2021
2267
|
*/
|
|
2022
|
-
|
|
2268
|
+
createHref(location: Location | URL): string;
|
|
2023
2269
|
/**
|
|
2024
|
-
*
|
|
2025
|
-
*
|
|
2270
|
+
* @private
|
|
2271
|
+
* PRIVATE - DO NOT USE
|
|
2272
|
+
*
|
|
2273
|
+
* Utility function to URL encode a destination path according to the internal
|
|
2274
|
+
* history implementation
|
|
2275
|
+
* @param to
|
|
2026
2276
|
*/
|
|
2027
|
-
|
|
2277
|
+
encodeLocation(to: To): Path;
|
|
2028
2278
|
/**
|
|
2029
|
-
*
|
|
2030
|
-
*
|
|
2279
|
+
* @private
|
|
2280
|
+
* PRIVATE - DO NOT USE
|
|
2281
|
+
*
|
|
2282
|
+
* Get/create a fetcher for the given key
|
|
2283
|
+
* @param key
|
|
2031
2284
|
*/
|
|
2032
|
-
|
|
2285
|
+
getFetcher<TData = any>(key: string): Fetcher<TData>;
|
|
2033
2286
|
/**
|
|
2034
|
-
*
|
|
2035
|
-
*
|
|
2287
|
+
* @internal
|
|
2288
|
+
* PRIVATE - DO NOT USE
|
|
2289
|
+
*
|
|
2290
|
+
* Reset the fetcher for a given key
|
|
2291
|
+
* @param key
|
|
2036
2292
|
*/
|
|
2037
|
-
|
|
2293
|
+
resetFetcher(key: string, opts?: {
|
|
2294
|
+
reason?: unknown;
|
|
2295
|
+
}): void;
|
|
2038
2296
|
/**
|
|
2039
|
-
*
|
|
2040
|
-
*
|
|
2297
|
+
* @private
|
|
2298
|
+
* PRIVATE - DO NOT USE
|
|
2299
|
+
*
|
|
2300
|
+
* Delete the fetcher for a given key
|
|
2301
|
+
* @param key
|
|
2041
2302
|
*/
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
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 {
|
|
2303
|
+
deleteFetcher(key: string): void;
|
|
2304
|
+
/**
|
|
2305
|
+
* @private
|
|
2306
|
+
* PRIVATE - DO NOT USE
|
|
2307
|
+
*
|
|
2308
|
+
* Cleanup listeners and abort any in-progress loads
|
|
2309
|
+
*/
|
|
2310
|
+
dispose(): void;
|
|
2106
2311
|
/**
|
|
2107
|
-
*
|
|
2312
|
+
* @private
|
|
2313
|
+
* PRIVATE - DO NOT USE
|
|
2314
|
+
*
|
|
2315
|
+
* Get a navigation blocker
|
|
2316
|
+
* @param key The identifier for the blocker
|
|
2317
|
+
* @param fn The blocker function implementation
|
|
2108
2318
|
*/
|
|
2109
|
-
|
|
2319
|
+
getBlocker(key: string, fn: BlockerFunction): Blocker;
|
|
2110
2320
|
/**
|
|
2111
|
-
*
|
|
2321
|
+
* @private
|
|
2322
|
+
* PRIVATE - DO NOT USE
|
|
2323
|
+
*
|
|
2324
|
+
* Delete a navigation blocker
|
|
2325
|
+
* @param key The identifier for the blocker
|
|
2112
2326
|
*/
|
|
2113
|
-
|
|
2327
|
+
deleteBlocker(key: string): void;
|
|
2114
2328
|
/**
|
|
2115
|
-
*
|
|
2116
|
-
*
|
|
2329
|
+
* @private
|
|
2330
|
+
* PRIVATE DO NOT USE
|
|
2331
|
+
*
|
|
2332
|
+
* Patch additional children routes into an existing parent route
|
|
2333
|
+
* @param routeId The parent route id or a callback function accepting `patch`
|
|
2334
|
+
* to perform batch patching
|
|
2335
|
+
* @param children The additional children routes
|
|
2336
|
+
* @param unstable_allowElementMutations Allow mutation or route elements on
|
|
2337
|
+
* existing routes. Intended for RSC-usage
|
|
2338
|
+
* only.
|
|
2117
2339
|
*/
|
|
2118
|
-
|
|
2340
|
+
patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
|
|
2119
2341
|
/**
|
|
2120
|
-
*
|
|
2121
|
-
*
|
|
2342
|
+
* @private
|
|
2343
|
+
* PRIVATE - DO NOT USE
|
|
2344
|
+
*
|
|
2345
|
+
* HMR needs to pass in-flight route updates to React Router
|
|
2346
|
+
* TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
|
|
2122
2347
|
*/
|
|
2123
|
-
|
|
2348
|
+
_internalSetRoutes(routes: AgnosticRouteObject[]): void;
|
|
2124
2349
|
/**
|
|
2125
|
-
*
|
|
2126
|
-
*
|
|
2350
|
+
* @private
|
|
2351
|
+
* PRIVATE - DO NOT USE
|
|
2352
|
+
*
|
|
2353
|
+
* Cause subscribers to re-render. This is used to force a re-render.
|
|
2127
2354
|
*/
|
|
2128
|
-
|
|
2355
|
+
_internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
|
|
2129
2356
|
/**
|
|
2130
|
-
*
|
|
2131
|
-
*
|
|
2357
|
+
* @private
|
|
2358
|
+
* PRIVATE - DO NOT USE
|
|
2359
|
+
*
|
|
2360
|
+
* Internal fetch AbortControllers accessed by unit tests
|
|
2132
2361
|
*/
|
|
2133
|
-
|
|
2362
|
+
_internalFetchControllers: Map<string, AbortController>;
|
|
2134
2363
|
}
|
|
2135
2364
|
/**
|
|
2136
|
-
*
|
|
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
|
|
2365
|
+
* State maintained internally by the router. During a navigation, all states
|
|
2366
|
+
* reflect the "old" location unless otherwise noted.
|
|
2158
2367
|
*/
|
|
2159
|
-
interface
|
|
2368
|
+
interface RouterState {
|
|
2160
2369
|
/**
|
|
2161
|
-
*
|
|
2370
|
+
* The action of the most recent navigation
|
|
2162
2371
|
*/
|
|
2163
|
-
|
|
2372
|
+
historyAction: Action;
|
|
2164
2373
|
/**
|
|
2165
|
-
* The
|
|
2374
|
+
* The current location reflected by the router
|
|
2166
2375
|
*/
|
|
2167
|
-
location
|
|
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> {
|
|
2376
|
+
location: Location;
|
|
2199
2377
|
/**
|
|
2200
|
-
*
|
|
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
|
-
* ```
|
|
2378
|
+
* The current set of route matches
|
|
2221
2379
|
*/
|
|
2222
|
-
|
|
2380
|
+
matches: AgnosticDataRouteMatch[];
|
|
2223
2381
|
/**
|
|
2224
|
-
*
|
|
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.
|
|
2382
|
+
* Tracks whether we've completed our initial data load
|
|
2256
2383
|
*/
|
|
2257
|
-
|
|
2384
|
+
initialized: boolean;
|
|
2258
2385
|
/**
|
|
2259
|
-
*
|
|
2260
|
-
*
|
|
2261
|
-
*
|
|
2262
|
-
*
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
*
|
|
2267
|
-
*
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
*
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
*
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
*
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
*
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
*
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
*
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
*
|
|
2296
|
-
* ```
|
|
2386
|
+
* Current scroll position we should start at for a new view
|
|
2387
|
+
* - number -> scroll position to restore to
|
|
2388
|
+
* - false -> do not restore scroll at all (used during submissions/revalidations)
|
|
2389
|
+
* - null -> don't have a saved position, scroll to hash or top of page
|
|
2390
|
+
*/
|
|
2391
|
+
restoreScrollPosition: number | false | null;
|
|
2392
|
+
/**
|
|
2393
|
+
* Indicate whether this navigation should skip resetting the scroll position
|
|
2394
|
+
* if we are unable to restore the scroll position
|
|
2395
|
+
*/
|
|
2396
|
+
preventScrollReset: boolean;
|
|
2397
|
+
/**
|
|
2398
|
+
* Tracks the state of the current navigation
|
|
2399
|
+
*/
|
|
2400
|
+
navigation: Navigation;
|
|
2401
|
+
/**
|
|
2402
|
+
* Tracks any in-progress revalidations
|
|
2403
|
+
*/
|
|
2404
|
+
revalidation: RevalidationState;
|
|
2405
|
+
/**
|
|
2406
|
+
* Data from the loaders for the current matches
|
|
2407
|
+
*/
|
|
2408
|
+
loaderData: RouteData;
|
|
2409
|
+
/**
|
|
2410
|
+
* Data from the action for the current matches
|
|
2411
|
+
*/
|
|
2412
|
+
actionData: RouteData | null;
|
|
2413
|
+
/**
|
|
2414
|
+
* Errors caught from loaders for the current matches
|
|
2415
|
+
*/
|
|
2416
|
+
errors: RouteData | null;
|
|
2417
|
+
/**
|
|
2418
|
+
* Map of current fetchers
|
|
2419
|
+
*/
|
|
2420
|
+
fetchers: Map<string, Fetcher>;
|
|
2421
|
+
/**
|
|
2422
|
+
* Map of current blockers
|
|
2297
2423
|
*/
|
|
2298
|
-
|
|
2424
|
+
blockers: Map<string, Blocker>;
|
|
2299
2425
|
}
|
|
2300
2426
|
/**
|
|
2301
|
-
*
|
|
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
|
|
2427
|
+
* Data that can be passed into hydrate a Router from SSR
|
|
2346
2428
|
*/
|
|
2347
|
-
|
|
2429
|
+
type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
|
|
2348
2430
|
/**
|
|
2349
|
-
*
|
|
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}
|
|
2431
|
+
* Future flags to toggle new feature behavior
|
|
2358
2432
|
*/
|
|
2359
|
-
|
|
2433
|
+
interface FutureConfig {
|
|
2434
|
+
}
|
|
2360
2435
|
/**
|
|
2361
|
-
*
|
|
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}
|
|
2436
|
+
* Initialization options for createRouter
|
|
2387
2437
|
*/
|
|
2388
|
-
|
|
2438
|
+
interface RouterInit {
|
|
2439
|
+
routes: AgnosticRouteObject[];
|
|
2440
|
+
history: History;
|
|
2441
|
+
basename?: string;
|
|
2442
|
+
getContext?: () => MaybePromise<RouterContextProvider>;
|
|
2443
|
+
unstable_instrumentations?: unstable_ClientInstrumentation[];
|
|
2444
|
+
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
2445
|
+
future?: Partial<FutureConfig>;
|
|
2446
|
+
hydrationRouteProperties?: string[];
|
|
2447
|
+
hydrationData?: HydrationState;
|
|
2448
|
+
window?: Window;
|
|
2449
|
+
dataStrategy?: DataStrategyFunction;
|
|
2450
|
+
patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
|
|
2451
|
+
}
|
|
2389
2452
|
/**
|
|
2390
|
-
*
|
|
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
|
|
2453
|
+
* State returned from a server-side query() call
|
|
2396
2454
|
*/
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
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> {
|
|
2455
|
+
interface StaticHandlerContext {
|
|
2456
|
+
basename: Router["basename"];
|
|
2457
|
+
location: RouterState["location"];
|
|
2458
|
+
matches: RouterState["matches"];
|
|
2459
|
+
loaderData: RouterState["loaderData"];
|
|
2460
|
+
actionData: RouterState["actionData"];
|
|
2461
|
+
errors: RouterState["errors"];
|
|
2462
|
+
statusCode: number;
|
|
2463
|
+
loaderHeaders: Record<string, Headers>;
|
|
2464
|
+
actionHeaders: Record<string, Headers>;
|
|
2465
|
+
_deepestRenderedBoundaryId?: string | null;
|
|
2496
2466
|
}
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2467
|
+
/**
|
|
2468
|
+
* A StaticHandler instance manages a singular SSR navigation/fetch event
|
|
2469
|
+
*/
|
|
2470
|
+
interface StaticHandler {
|
|
2471
|
+
dataRoutes: AgnosticDataRouteObject[];
|
|
2472
|
+
query(request: Request, opts?: {
|
|
2473
|
+
requestContext?: unknown;
|
|
2474
|
+
filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
|
|
2475
|
+
skipLoaderErrorBubbling?: boolean;
|
|
2476
|
+
skipRevalidation?: boolean;
|
|
2477
|
+
dataStrategy?: DataStrategyFunction<unknown>;
|
|
2478
|
+
generateMiddlewareResponse?: (query: (r: Request, args?: {
|
|
2479
|
+
filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
|
|
2480
|
+
}) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
2481
|
+
}): Promise<StaticHandlerContext | Response>;
|
|
2482
|
+
queryRoute(request: Request, opts?: {
|
|
2483
|
+
routeId?: string;
|
|
2484
|
+
requestContext?: unknown;
|
|
2485
|
+
dataStrategy?: DataStrategyFunction<unknown>;
|
|
2486
|
+
generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
|
|
2487
|
+
}): Promise<any>;
|
|
2503
2488
|
}
|
|
2504
|
-
|
|
2505
|
-
declare const DataRouterStateContext: React.Context<RouterState | null>;
|
|
2506
|
-
type ViewTransitionContextObject = {
|
|
2507
|
-
isTransitioning: false;
|
|
2508
|
-
} | {
|
|
2509
|
-
isTransitioning: true;
|
|
2510
|
-
flushSync: boolean;
|
|
2489
|
+
type ViewTransitionOpts = {
|
|
2511
2490
|
currentLocation: Location;
|
|
2512
2491
|
nextLocation: Location;
|
|
2513
2492
|
};
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2493
|
+
/**
|
|
2494
|
+
* Subscriber function signature for changes to router state
|
|
2495
|
+
*/
|
|
2496
|
+
interface RouterSubscriber {
|
|
2497
|
+
(state: RouterState, opts: {
|
|
2498
|
+
deletedFetchers: string[];
|
|
2499
|
+
viewTransitionOpts?: ViewTransitionOpts;
|
|
2500
|
+
flushSync: boolean;
|
|
2501
|
+
}): void;
|
|
2502
|
+
}
|
|
2503
|
+
/**
|
|
2504
|
+
* Function signature for determining the key to be used in scroll restoration
|
|
2505
|
+
* for a given location
|
|
2506
|
+
*/
|
|
2507
|
+
interface GetScrollRestorationKeyFunction {
|
|
2508
|
+
(location: Location, matches: UIMatch[]): string | null;
|
|
2509
|
+
}
|
|
2510
|
+
/**
|
|
2511
|
+
* Function signature for determining the current scroll position
|
|
2512
|
+
*/
|
|
2513
|
+
interface GetScrollPositionFunction {
|
|
2514
|
+
(): number;
|
|
2515
|
+
}
|
|
2516
|
+
/**
|
|
2517
|
+
* - "route": relative to the route hierarchy so `..` means remove all segments
|
|
2518
|
+
* of the current route even if it has many. For example, a `route("posts/:id")`
|
|
2519
|
+
* would have both `:id` and `posts` removed from the url.
|
|
2520
|
+
* - "path": relative to the pathname so `..` means remove one segment of the
|
|
2521
|
+
* pathname. For example, a `route("posts/:id")` would have only `:id` removed
|
|
2522
|
+
* from the url.
|
|
2523
|
+
*/
|
|
2524
|
+
type RelativeRoutingType = "route" | "path";
|
|
2525
|
+
type BaseNavigateOrFetchOptions = {
|
|
2525
2526
|
preventScrollReset?: boolean;
|
|
2526
|
-
/** Defines the relative path behavior for the link. "route" will use the route hierarchy so ".." will remove all URL segments of the current route pattern while "path" will use the URL path so ".." will remove one URL segment. */
|
|
2527
2527
|
relative?: RelativeRoutingType;
|
|
2528
|
-
/** Wraps the initial state update for this navigation in a {@link https://react.dev/reference/react-dom/flushSync ReactDOM.flushSync} call instead of the default {@link https://react.dev/reference/react/startTransition React.startTransition} */
|
|
2529
2528
|
flushSync?: boolean;
|
|
2530
|
-
|
|
2529
|
+
};
|
|
2530
|
+
type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
|
|
2531
|
+
replace?: boolean;
|
|
2532
|
+
state?: any;
|
|
2533
|
+
fromRouteId?: string;
|
|
2531
2534
|
viewTransition?: boolean;
|
|
2532
|
-
}
|
|
2535
|
+
};
|
|
2536
|
+
type BaseSubmissionOptions = {
|
|
2537
|
+
formMethod?: HTMLFormMethod;
|
|
2538
|
+
formEncType?: FormEncType;
|
|
2539
|
+
} & ({
|
|
2540
|
+
formData: FormData;
|
|
2541
|
+
body?: undefined;
|
|
2542
|
+
} | {
|
|
2543
|
+
formData?: undefined;
|
|
2544
|
+
body: any;
|
|
2545
|
+
});
|
|
2533
2546
|
/**
|
|
2534
|
-
*
|
|
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.
|
|
2547
|
+
* Options for a navigate() call for a normal (non-submission) navigation
|
|
2541
2548
|
*/
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2549
|
+
type LinkNavigateOptions = BaseNavigateOptions;
|
|
2550
|
+
/**
|
|
2551
|
+
* Options for a navigate() call for a submission navigation
|
|
2552
|
+
*/
|
|
2553
|
+
type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
|
|
2554
|
+
/**
|
|
2555
|
+
* Options to pass to navigate() for a navigation
|
|
2556
|
+
*/
|
|
2557
|
+
type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
|
|
2558
|
+
/**
|
|
2559
|
+
* Options for a fetch() load
|
|
2560
|
+
*/
|
|
2561
|
+
type LoadFetchOptions = BaseNavigateOrFetchOptions;
|
|
2562
|
+
/**
|
|
2563
|
+
* Options for a fetch() submission
|
|
2564
|
+
*/
|
|
2565
|
+
type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
|
|
2566
|
+
/**
|
|
2567
|
+
* Options to pass to fetch()
|
|
2568
|
+
*/
|
|
2569
|
+
type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
|
|
2570
|
+
/**
|
|
2571
|
+
* Potential states for state.navigation
|
|
2572
|
+
*/
|
|
2573
|
+
type NavigationStates = {
|
|
2574
|
+
Idle: {
|
|
2575
|
+
state: "idle";
|
|
2576
|
+
location: undefined;
|
|
2577
|
+
formMethod: undefined;
|
|
2578
|
+
formAction: undefined;
|
|
2579
|
+
formEncType: undefined;
|
|
2580
|
+
formData: undefined;
|
|
2581
|
+
json: undefined;
|
|
2582
|
+
text: undefined;
|
|
2583
|
+
};
|
|
2584
|
+
Loading: {
|
|
2585
|
+
state: "loading";
|
|
2586
|
+
location: Location;
|
|
2587
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
2588
|
+
formAction: Submission["formAction"] | undefined;
|
|
2589
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
2590
|
+
formData: Submission["formData"] | undefined;
|
|
2591
|
+
json: Submission["json"] | undefined;
|
|
2592
|
+
text: Submission["text"] | undefined;
|
|
2593
|
+
};
|
|
2594
|
+
Submitting: {
|
|
2595
|
+
state: "submitting";
|
|
2596
|
+
location: Location;
|
|
2597
|
+
formMethod: Submission["formMethod"];
|
|
2598
|
+
formAction: Submission["formAction"];
|
|
2599
|
+
formEncType: Submission["formEncType"];
|
|
2600
|
+
formData: Submission["formData"];
|
|
2601
|
+
json: Submission["json"];
|
|
2602
|
+
text: Submission["text"];
|
|
2603
|
+
};
|
|
2604
|
+
};
|
|
2605
|
+
type Navigation = NavigationStates[keyof NavigationStates];
|
|
2606
|
+
type RevalidationState = "idle" | "loading";
|
|
2607
|
+
/**
|
|
2608
|
+
* Potential states for fetchers
|
|
2609
|
+
*/
|
|
2610
|
+
type FetcherStates<TData = any> = {
|
|
2611
|
+
/**
|
|
2612
|
+
* The fetcher is not calling a loader or action
|
|
2613
|
+
*
|
|
2614
|
+
* ```tsx
|
|
2615
|
+
* fetcher.state === "idle"
|
|
2616
|
+
* ```
|
|
2617
|
+
*/
|
|
2618
|
+
Idle: {
|
|
2619
|
+
state: "idle";
|
|
2620
|
+
formMethod: undefined;
|
|
2621
|
+
formAction: undefined;
|
|
2622
|
+
formEncType: undefined;
|
|
2623
|
+
text: undefined;
|
|
2624
|
+
formData: undefined;
|
|
2625
|
+
json: undefined;
|
|
2626
|
+
/**
|
|
2627
|
+
* If the fetcher has never been called, this will be undefined.
|
|
2628
|
+
*/
|
|
2629
|
+
data: TData | undefined;
|
|
2630
|
+
};
|
|
2631
|
+
/**
|
|
2632
|
+
* The fetcher is loading data from a {@link LoaderFunction | loader} from a
|
|
2633
|
+
* call to {@link FetcherWithComponents.load | `fetcher.load`}.
|
|
2634
|
+
*
|
|
2635
|
+
* ```tsx
|
|
2636
|
+
* // somewhere
|
|
2637
|
+
* <button onClick={() => fetcher.load("/some/route") }>Load</button>
|
|
2638
|
+
*
|
|
2639
|
+
* // the state will update
|
|
2640
|
+
* fetcher.state === "loading"
|
|
2641
|
+
* ```
|
|
2642
|
+
*/
|
|
2643
|
+
Loading: {
|
|
2644
|
+
state: "loading";
|
|
2645
|
+
formMethod: Submission["formMethod"] | undefined;
|
|
2646
|
+
formAction: Submission["formAction"] | undefined;
|
|
2647
|
+
formEncType: Submission["formEncType"] | undefined;
|
|
2648
|
+
text: Submission["text"] | undefined;
|
|
2649
|
+
formData: Submission["formData"] | undefined;
|
|
2650
|
+
json: Submission["json"] | undefined;
|
|
2651
|
+
data: TData | undefined;
|
|
2652
|
+
};
|
|
2653
|
+
/**
|
|
2654
|
+
The fetcher is submitting to a {@link LoaderFunction} (GET) or {@link ActionFunction} (POST) from a {@link FetcherWithComponents.Form | `fetcher.Form`} or {@link FetcherWithComponents.submit | `fetcher.submit`}.
|
|
2655
|
+
|
|
2656
|
+
```tsx
|
|
2657
|
+
// somewhere
|
|
2658
|
+
<input
|
|
2659
|
+
onChange={e => {
|
|
2660
|
+
fetcher.submit(event.currentTarget.form, { method: "post" });
|
|
2661
|
+
}}
|
|
2662
|
+
/>
|
|
2663
|
+
|
|
2664
|
+
// the state will update
|
|
2665
|
+
fetcher.state === "submitting"
|
|
2666
|
+
|
|
2667
|
+
// and formData will be available
|
|
2668
|
+
fetcher.formData
|
|
2669
|
+
```
|
|
2670
|
+
*/
|
|
2671
|
+
Submitting: {
|
|
2672
|
+
state: "submitting";
|
|
2673
|
+
formMethod: Submission["formMethod"];
|
|
2674
|
+
formAction: Submission["formAction"];
|
|
2675
|
+
formEncType: Submission["formEncType"];
|
|
2676
|
+
text: Submission["text"];
|
|
2677
|
+
formData: Submission["formData"];
|
|
2678
|
+
json: Submission["json"];
|
|
2679
|
+
data: TData | undefined;
|
|
2680
|
+
};
|
|
2681
|
+
};
|
|
2682
|
+
type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
|
|
2683
|
+
interface BlockerBlocked {
|
|
2684
|
+
state: "blocked";
|
|
2685
|
+
reset: () => void;
|
|
2686
|
+
proceed: () => void;
|
|
2687
|
+
location: Location;
|
|
2548
2688
|
}
|
|
2549
|
-
interface
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2689
|
+
interface BlockerUnblocked {
|
|
2690
|
+
state: "unblocked";
|
|
2691
|
+
reset: undefined;
|
|
2692
|
+
proceed: undefined;
|
|
2693
|
+
location: undefined;
|
|
2554
2694
|
}
|
|
2555
|
-
|
|
2556
|
-
|
|
2695
|
+
interface BlockerProceeding {
|
|
2696
|
+
state: "proceeding";
|
|
2697
|
+
reset: undefined;
|
|
2698
|
+
proceed: undefined;
|
|
2557
2699
|
location: Location;
|
|
2558
|
-
navigationType: Action;
|
|
2559
2700
|
}
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2701
|
+
type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
|
|
2702
|
+
type BlockerFunction = (args: {
|
|
2703
|
+
currentLocation: Location;
|
|
2704
|
+
nextLocation: Location;
|
|
2705
|
+
historyAction: Action;
|
|
2706
|
+
}) => boolean;
|
|
2707
|
+
declare const IDLE_NAVIGATION: NavigationStates["Idle"];
|
|
2708
|
+
declare const IDLE_FETCHER: FetcherStates["Idle"];
|
|
2709
|
+
declare const IDLE_BLOCKER: BlockerUnblocked;
|
|
2710
|
+
/**
|
|
2711
|
+
* Create a router and listen to history POP navigations
|
|
2712
|
+
*/
|
|
2713
|
+
declare function createRouter(init: RouterInit): Router;
|
|
2714
|
+
interface CreateStaticHandlerOptions {
|
|
2715
|
+
basename?: string;
|
|
2716
|
+
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
2717
|
+
unstable_instrumentations?: Pick<unstable_ServerInstrumentation, "route">[];
|
|
2718
|
+
future?: {};
|
|
2565
2719
|
}
|
|
2566
|
-
declare const RouteContext: React.Context<RouteContextObject>;
|
|
2567
2720
|
|
|
2568
|
-
export { type
|
|
2721
|
+
export { type DataStrategyFunctionArgs as $, type ActionFunctionArgs as A, type BlockerFunction as B, type RouterState as C, type DataStrategyResult as D, type ErrorBoundaryType as E, type PatchRoutesOnNavigationFunction as F, type DataRouteObject as G, type HydrationState as H, type InitialEntry as I, type StaticHandler as J, type GetScrollPositionFunction as K, type Location as L, type MiddlewareNextFunction as M, type NavigateOptions as N, type GetScrollRestorationKeyFunction as O, type Params as P, type StaticHandlerContext as Q, type RouterProviderProps as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type Fetcher as V, type NavigationStates as W, type RouterSubscriber as X, type RouterNavigateOptions as Y, type RouterFetchOptions as Z, type RevalidationState as _, type RouterInit as a, ViewTransitionContext 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 PathRouteProps as aA, type RouteProps as aB, type RouterProps as aC, type RoutesProps as aD, Await as aE, MemoryRouter as aF, Navigate as aG, Outlet as aH, Route as aI, Router$1 as aJ, RouterProvider as aK, Routes as aL, createMemoryRouter as aM, createRoutesFromChildren as aN, createRoutesFromElements as aO, renderMatches as aP, type Future as aQ, createBrowserHistory as aR, invariant as aS, createRouter as aT, ErrorResponseImpl as aU, DataRouterContext as aV, DataRouterStateContext as aW, FetchersContext as aX, LocationContext as aY, NavigationContext as aZ, RouteContext as a_, createContext as aa, createPath as ab, parsePath as ac, IDLE_NAVIGATION as ad, IDLE_FETCHER as ae, IDLE_BLOCKER as af, data as ag, generatePath as ah, isRouteErrorResponse as ai, matchPath as aj, matchRoutes as ak, redirect as al, redirectDocument as am, replace as an, resolvePath as ao, type Navigator as ap, type PatchRoutesOnNavigationFunctionArgs as aq, type RouteMatch as ar, AwaitContextProvider as as, type AwaitProps as at, type IndexRouteProps as au, type LayoutRouteProps as av, type MemoryRouterOpts as aw, type MemoryRouterProps as ax, type NavigateProps as ay, type OutletProps as az, type unstable_ClientOnErrorFunction as b, hydrationRouteProperties as b0, mapRouteProperties as b1, WithComponentProps as b2, withComponentProps as b3, WithHydrateFallbackProps as b4, withHydrateFallbackProps as b5, WithErrorBoundaryProps as b6, withErrorBoundaryProps as b7, type RouteManifest as b8, type unstable_ServerInstrumentation as b9, type History as ba, type FutureConfig as bb, type CreateStaticHandlerOptions as bc, 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 };
|