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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/development/{chunk-ZLVXSGFL.js → chunk-2G2U5HGB.js} +161 -164
  2. package/dist/development/{chunk-CWSJ6RYI.mjs → chunk-AGOH44BE.mjs} +51 -67
  3. package/dist/development/{chunk-47MIYFLC.mjs → chunk-IMKEG5CI.mjs} +29 -309
  4. package/dist/development/{chunk-QOFB7XZ5.js → chunk-LUB73E44.js} +70 -347
  5. package/dist/development/{router-DQIRhYoj.d.mts → context-BqL5Eckq.d.mts} +1288 -1441
  6. package/dist/development/dom-export.d.mts +4 -59
  7. package/dist/development/dom-export.d.ts +3 -59
  8. package/dist/development/dom-export.js +5 -8
  9. package/dist/development/dom-export.mjs +5 -8
  10. package/dist/{production/index-react-server-client-lf74v6ET.d.mts → development/index-react-server-client-2EDmGlsZ.d.mts} +77 -140
  11. package/dist/development/{index-react-server-client-lf74v6ET.d.mts → index-react-server-client-DKvU8YRr.d.ts} +134 -198
  12. package/dist/development/index-react-server-client.d.mts +3 -3
  13. package/dist/development/index-react-server-client.d.ts +2 -3
  14. package/dist/development/index-react-server-client.js +4 -4
  15. package/dist/development/index-react-server-client.mjs +2 -2
  16. package/dist/development/index-react-server.d.mts +1 -106
  17. package/dist/development/index-react-server.d.ts +1 -106
  18. package/dist/development/index-react-server.js +8 -181
  19. package/dist/development/index-react-server.mjs +8 -181
  20. package/dist/development/index.d.mts +20 -13
  21. package/dist/development/index.d.ts +18 -13
  22. package/dist/development/index.js +147 -161
  23. package/dist/development/index.mjs +5 -3
  24. package/dist/development/lib/types/internal.d.mts +3 -3
  25. package/dist/development/lib/types/internal.d.ts +2 -3
  26. package/dist/development/lib/types/internal.js +1 -1
  27. package/dist/development/lib/types/internal.mjs +1 -1
  28. package/dist/development/{register-DiOIlEq5.d.mts → register-BrVEYTED.d.mts} +7 -1
  29. package/dist/{production/register-DiOIlEq5.d.mts → development/register-D8NQoPsO.d.ts} +7 -1
  30. package/dist/development/{routeModules--SgCTStn.d.mts → route-data-CDwqkzPE.d.mts} +147 -157
  31. package/dist/{production/routeModules-rxNxBmdR.d.ts → development/routeModules-BmVo7q9e.d.ts} +1046 -73
  32. package/dist/production/{chunk-ZOHTOBOT.js → chunk-2L5AG5Y5.js} +70 -347
  33. package/dist/production/{chunk-UAAA7FTX.mjs → chunk-AODJW4D3.mjs} +51 -67
  34. package/dist/production/{chunk-4SPSFXAZ.js → chunk-FGRCWJDI.js} +161 -164
  35. package/dist/production/{chunk-MMAHTIVZ.mjs → chunk-UOQCOPF6.mjs} +29 -309
  36. package/dist/production/{router-DQIRhYoj.d.mts → context-BqL5Eckq.d.mts} +1288 -1441
  37. package/dist/production/dom-export.d.mts +4 -59
  38. package/dist/production/dom-export.d.ts +3 -59
  39. package/dist/production/dom-export.js +5 -8
  40. package/dist/production/dom-export.mjs +5 -8
  41. package/dist/{development/index-react-server-client-Iw2PMej2.d.ts → production/index-react-server-client-2EDmGlsZ.d.mts} +77 -140
  42. package/dist/production/{index-react-server-client-Iw2PMej2.d.ts → index-react-server-client-DKvU8YRr.d.ts} +134 -198
  43. package/dist/production/index-react-server-client.d.mts +3 -3
  44. package/dist/production/index-react-server-client.d.ts +2 -3
  45. package/dist/production/index-react-server-client.js +4 -4
  46. package/dist/production/index-react-server-client.mjs +2 -2
  47. package/dist/production/index-react-server.d.mts +1 -106
  48. package/dist/production/index-react-server.d.ts +1 -106
  49. package/dist/production/index-react-server.js +8 -181
  50. package/dist/production/index-react-server.mjs +8 -181
  51. package/dist/production/index.d.mts +20 -13
  52. package/dist/production/index.d.ts +18 -13
  53. package/dist/production/index.js +147 -161
  54. package/dist/production/index.mjs +5 -3
  55. package/dist/production/lib/types/internal.d.mts +3 -3
  56. package/dist/production/lib/types/internal.d.ts +2 -3
  57. package/dist/production/lib/types/internal.js +1 -1
  58. package/dist/production/lib/types/internal.mjs +1 -1
  59. package/dist/{development/register-DiOIlEq5.d.ts → production/register-BrVEYTED.d.mts} +7 -1
  60. package/dist/production/{register-DiOIlEq5.d.ts → register-D8NQoPsO.d.ts} +7 -1
  61. package/dist/production/{routeModules--SgCTStn.d.mts → route-data-CDwqkzPE.d.mts} +147 -157
  62. package/dist/{development/routeModules-rxNxBmdR.d.ts → production/routeModules-BmVo7q9e.d.ts} +1046 -73
  63. package/package.json +1 -1
  64. package/dist/development/instrumentation-BWRz1MRU.d.ts +0 -1138
  65. package/dist/production/instrumentation-BWRz1MRU.d.ts +0 -1138
@@ -1,16 +1,1044 @@
1
1
  import * as React from 'react';
2
2
  import { ComponentType, ReactElement } from 'react';
3
- import { A as AgnosticRouteObject, H as History, a as MaybePromise, R as RouterContextProvider, u as unstable_ClientInstrumentation, b as MapRoutePropertiesFunction, c as Action, L as Location, d as AgnosticDataRouteMatch, S as Submission, e as RouteData, f as DataStrategyFunction, g as AgnosticPatchRoutesOnNavigationFunction, h as AgnosticDataRouteObject, U as UIMatch, T as To, i as HTMLFormMethod, F as FormEncType, P as Path, j as unstable_ServerInstrumentation, I as InitialEntry, k as LazyRouteFunction, l as Params, m as TrackedPromise, n as AgnosticNonIndexRouteObject, o as AgnosticIndexRouteObject, p as LazyRouteDefinition, q as AgnosticRouteMatch, r as AgnosticPatchRoutesOnNavigationFunctionArgs, s as DataWithResponseInit, t as MiddlewareEnabled, v as ActionFunctionArgs, w as LoaderFunctionArgs, x as ActionFunction, y as LoaderFunction, z as MiddlewareFunction, D as DataStrategyResult, B as ShouldRevalidateFunction } from './instrumentation-BWRz1MRU.js';
4
3
 
5
4
  /**
6
- * An object of unknown type for route loaders and actions provided by the
7
- * server's `getLoadContext()` function. This is defined as an empty interface
8
- * specifically so apps can leverage declaration merging to augment this type
9
- * globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
5
+ * Actions represent the type of change to a location value.
10
6
  */
11
- interface AppLoadContext {
12
- [key: string]: unknown;
7
+ declare enum Action {
8
+ /**
9
+ * A POP indicates a change to an arbitrary index in the history stack, such
10
+ * as a back or forward navigation. It does not describe the direction of the
11
+ * navigation, only that the current index changed.
12
+ *
13
+ * Note: This is the default action for newly created history objects.
14
+ */
15
+ Pop = "POP",
16
+ /**
17
+ * A PUSH indicates a new entry being added to the history stack, such as when
18
+ * a link is clicked and a new page loads. When this happens, all subsequent
19
+ * entries in the stack are lost.
20
+ */
21
+ Push = "PUSH",
22
+ /**
23
+ * A REPLACE indicates the entry at the current index in the history stack
24
+ * being replaced by a new one.
25
+ */
26
+ Replace = "REPLACE"
27
+ }
28
+ /**
29
+ * The pathname, search, and hash values of a URL.
30
+ */
31
+ interface Path {
32
+ /**
33
+ * A URL pathname, beginning with a /.
34
+ */
35
+ pathname: string;
36
+ /**
37
+ * A URL search string, beginning with a ?.
38
+ */
39
+ search: string;
40
+ /**
41
+ * A URL fragment identifier, beginning with a #.
42
+ */
43
+ hash: string;
13
44
  }
45
+ /**
46
+ * An entry in a history stack. A location contains information about the
47
+ * URL path, as well as possibly some arbitrary state and a key.
48
+ */
49
+ interface Location<State = any> extends Path {
50
+ /**
51
+ * A value of arbitrary data associated with this location.
52
+ */
53
+ state: State;
54
+ /**
55
+ * A unique string associated with this location. May be used to safely store
56
+ * and retrieve data in some other storage API, like `localStorage`.
57
+ *
58
+ * Note: This value is always "default" on the initial location.
59
+ */
60
+ key: string;
61
+ }
62
+ /**
63
+ * A change to the current location.
64
+ */
65
+ interface Update {
66
+ /**
67
+ * The action that triggered the change.
68
+ */
69
+ action: Action;
70
+ /**
71
+ * The new location.
72
+ */
73
+ location: Location;
74
+ /**
75
+ * The delta between this location and the former location in the history stack
76
+ */
77
+ delta: number | null;
78
+ }
79
+ /**
80
+ * A function that receives notifications about location changes.
81
+ */
82
+ interface Listener {
83
+ (update: Update): void;
84
+ }
85
+ /**
86
+ * Describes a location that is the destination of some navigation used in
87
+ * {@link Link}, {@link useNavigate}, etc.
88
+ */
89
+ type To = string | Partial<Path>;
90
+ /**
91
+ * A history is an interface to the navigation stack. The history serves as the
92
+ * source of truth for the current location, as well as provides a set of
93
+ * methods that may be used to change it.
94
+ *
95
+ * It is similar to the DOM's `window.history` object, but with a smaller, more
96
+ * focused API.
97
+ */
98
+ interface History {
99
+ /**
100
+ * The last action that modified the current location. This will always be
101
+ * Action.Pop when a history instance is first created. This value is mutable.
102
+ */
103
+ readonly action: Action;
104
+ /**
105
+ * The current location. This value is mutable.
106
+ */
107
+ readonly location: Location;
108
+ /**
109
+ * Returns a valid href for the given `to` value that may be used as
110
+ * the value of an <a href> attribute.
111
+ *
112
+ * @param to - The destination URL
113
+ */
114
+ createHref(to: To): string;
115
+ /**
116
+ * Returns a URL for the given `to` value
117
+ *
118
+ * @param to - The destination URL
119
+ */
120
+ createURL(to: To): URL;
121
+ /**
122
+ * Encode a location the same way window.history would do (no-op for memory
123
+ * history) so we ensure our PUSH/REPLACE navigations for data routers
124
+ * behave the same as POP
125
+ *
126
+ * @param to Unencoded path
127
+ */
128
+ encodeLocation(to: To): Path;
129
+ /**
130
+ * Pushes a new location onto the history stack, increasing its length by one.
131
+ * If there were any entries in the stack after the current one, they are
132
+ * lost.
133
+ *
134
+ * @param to - The new URL
135
+ * @param state - Data to associate with the new location
136
+ */
137
+ push(to: To, state?: any): void;
138
+ /**
139
+ * Replaces the current location in the history stack with a new one. The
140
+ * location that was replaced will no longer be available.
141
+ *
142
+ * @param to - The new URL
143
+ * @param state - Data to associate with the new location
144
+ */
145
+ replace(to: To, state?: any): void;
146
+ /**
147
+ * Navigates `n` entries backward/forward in the history stack relative to the
148
+ * current index. For example, a "back" navigation would use go(-1).
149
+ *
150
+ * @param delta - The delta in the stack index
151
+ */
152
+ go(delta: number): void;
153
+ /**
154
+ * Sets up a listener that will be called whenever the current location
155
+ * changes.
156
+ *
157
+ * @param listener - A function that will be called when the location changes
158
+ * @returns unlisten - A function that may be used to stop listening
159
+ */
160
+ listen(listener: Listener): () => void;
161
+ }
162
+ /**
163
+ * A user-supplied object that describes a location. Used when providing
164
+ * entries to `createMemoryHistory` via its `initialEntries` option.
165
+ */
166
+ type InitialEntry = string | Partial<Location>;
167
+ /**
168
+ * A browser history stores the current location in regular URLs in a web
169
+ * browser environment. This is the standard for most web apps and provides the
170
+ * cleanest URLs the browser's address bar.
171
+ *
172
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
173
+ */
174
+ interface BrowserHistory extends UrlHistory {
175
+ }
176
+ type BrowserHistoryOptions = UrlHistoryOptions;
177
+ /**
178
+ * Browser history stores the location in regular URLs. This is the standard for
179
+ * most web apps, but it requires some configuration on the server to ensure you
180
+ * serve the same app at multiple URLs.
181
+ *
182
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
183
+ */
184
+ declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
185
+ /**
186
+ * @private
187
+ */
188
+ declare function invariant(value: boolean, message?: string): asserts value;
189
+ declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
190
+ /**
191
+ * Creates a string URL path from the given pathname, search, and hash components.
192
+ *
193
+ * @category Utils
194
+ */
195
+ declare function createPath({ pathname, search, hash, }: Partial<Path>): string;
196
+ /**
197
+ * Parses a string URL path into its separate pathname, search, and hash components.
198
+ *
199
+ * @category Utils
200
+ */
201
+ declare function parsePath(path: string): Partial<Path>;
202
+ interface UrlHistory extends History {
203
+ }
204
+ type UrlHistoryOptions = {
205
+ window?: Window;
206
+ v5Compat?: boolean;
207
+ };
208
+
209
+ /**
210
+ * An augmentable interface users can modify in their app-code to opt into
211
+ * future-flag-specific types
212
+ */
213
+ interface Future {
214
+ }
215
+ type MiddlewareEnabled = Future extends {
216
+ v8_middleware: infer T extends boolean;
217
+ } ? T : false;
218
+
219
+ type MaybePromise<T> = T | Promise<T>;
220
+ /**
221
+ * Map of routeId -> data returned from a loader/action/error
222
+ */
223
+ interface RouteData {
224
+ [routeId: string]: any;
225
+ }
226
+ type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
227
+ type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
228
+ /**
229
+ * Users can specify either lowercase or uppercase form methods on `<Form>`,
230
+ * useSubmit(), `<fetcher.Form>`, etc.
231
+ */
232
+ type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
233
+ /**
234
+ * Active navigation/fetcher form methods are exposed in uppercase on the
235
+ * RouterState. This is to align with the normalization done via fetch().
236
+ */
237
+ type FormMethod = UpperCaseFormMethod;
238
+ type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
239
+ type JsonObject = {
240
+ [Key in string]: JsonValue;
241
+ } & {
242
+ [Key in string]?: JsonValue | undefined;
243
+ };
244
+ type JsonArray = JsonValue[] | readonly JsonValue[];
245
+ type JsonPrimitive = string | number | boolean | null;
246
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
247
+ /**
248
+ * @private
249
+ * Internal interface to pass around for action submissions, not intended for
250
+ * external consumption
251
+ */
252
+ type Submission = {
253
+ formMethod: FormMethod;
254
+ formAction: string;
255
+ formEncType: FormEncType;
256
+ formData: FormData;
257
+ json: undefined;
258
+ text: undefined;
259
+ } | {
260
+ formMethod: FormMethod;
261
+ formAction: string;
262
+ formEncType: FormEncType;
263
+ formData: undefined;
264
+ json: JsonValue;
265
+ text: undefined;
266
+ } | {
267
+ formMethod: FormMethod;
268
+ formAction: string;
269
+ formEncType: FormEncType;
270
+ formData: undefined;
271
+ json: undefined;
272
+ text: string;
273
+ };
274
+ /**
275
+ * A context instance used as the key for the `get`/`set` methods of a
276
+ * {@link RouterContextProvider}. Accepts an optional default
277
+ * value to be returned if no value has been set.
278
+ */
279
+ interface RouterContext<T = unknown> {
280
+ defaultValue?: T;
281
+ }
282
+ /**
283
+ * Creates a type-safe {@link RouterContext} object that can be used to
284
+ * store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
285
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
286
+ * Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
287
+ * but specifically designed for React Router's request/response lifecycle.
288
+ *
289
+ * If a `defaultValue` is provided, it will be returned from `context.get()`
290
+ * when no value has been set for the context. Otherwise, reading this context
291
+ * when no value has been set will throw an error.
292
+ *
293
+ * ```tsx filename=app/context.ts
294
+ * import { createContext } from "react-router";
295
+ *
296
+ * // Create a context for user data
297
+ * export const userContext =
298
+ * createContext<User | null>(null);
299
+ * ```
300
+ *
301
+ * ```tsx filename=app/middleware/auth.ts
302
+ * import { getUserFromSession } from "~/auth.server";
303
+ * import { userContext } from "~/context";
304
+ *
305
+ * export const authMiddleware = async ({
306
+ * context,
307
+ * request,
308
+ * }) => {
309
+ * const user = await getUserFromSession(request);
310
+ * context.set(userContext, user);
311
+ * };
312
+ * ```
313
+ *
314
+ * ```tsx filename=app/routes/profile.tsx
315
+ * import { userContext } from "~/context";
316
+ *
317
+ * export async function loader({
318
+ * context,
319
+ * }: Route.LoaderArgs) {
320
+ * const user = context.get(userContext);
321
+ *
322
+ * if (!user) {
323
+ * throw new Response("Unauthorized", { status: 401 });
324
+ * }
325
+ *
326
+ * return { user };
327
+ * }
328
+ * ```
329
+ *
330
+ * @public
331
+ * @category Utils
332
+ * @mode framework
333
+ * @mode data
334
+ * @param defaultValue An optional default value for the context. This value
335
+ * will be returned if no value has been set for this context.
336
+ * @returns A {@link RouterContext} object that can be used with
337
+ * `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
338
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
339
+ */
340
+ declare function createContext<T>(defaultValue?: T): RouterContext<T>;
341
+ /**
342
+ * Provides methods for writing/reading values in application context in a
343
+ * type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
344
+ *
345
+ * @example
346
+ * import {
347
+ * createContext,
348
+ * RouterContextProvider
349
+ * } from "react-router";
350
+ *
351
+ * const userContext = createContext<User | null>(null);
352
+ * const contextProvider = new RouterContextProvider();
353
+ * contextProvider.set(userContext, getUser());
354
+ * // ^ Type-safe
355
+ * const user = contextProvider.get(userContext);
356
+ * // ^ User
357
+ *
358
+ * @public
359
+ * @category Utils
360
+ * @mode framework
361
+ * @mode data
362
+ */
363
+ declare class RouterContextProvider {
364
+ #private;
365
+ /**
366
+ * Create a new `RouterContextProvider` instance
367
+ * @param init An optional initial context map to populate the provider with
368
+ */
369
+ constructor(init?: Map<RouterContext, unknown>);
370
+ /**
371
+ * Access a value from the context. If no value has been set for the context,
372
+ * it will return the context's `defaultValue` if provided, or throw an error
373
+ * if no `defaultValue` was set.
374
+ * @param context The context to get the value for
375
+ * @returns The value for the context, or the context's `defaultValue` if no
376
+ * value was set
377
+ */
378
+ get<T>(context: RouterContext<T>): T;
379
+ /**
380
+ * Set a value for the context. If the context already has a value set, this
381
+ * will overwrite it.
382
+ *
383
+ * @param context The context to set the value for
384
+ * @param value The value to set for the context
385
+ * @returns {void}
386
+ */
387
+ set<C extends RouterContext>(context: C, value: C extends RouterContext<infer T> ? T : never): void;
388
+ }
389
+ type DefaultContext = MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : any;
390
+ /**
391
+ * @private
392
+ * Arguments passed to route loader/action functions. Same for now but we keep
393
+ * this as a private implementation detail in case they diverge in the future.
394
+ */
395
+ interface DataFunctionArgs<Context> {
396
+ /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read headers (like cookies, and {@link https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams URLSearchParams} from the request. */
397
+ request: Request;
398
+ /**
399
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
400
+ * @example
401
+ * // app/routes.ts
402
+ * route("teams/:teamId", "./team.tsx"),
403
+ *
404
+ * // app/team.tsx
405
+ * export function loader({
406
+ * params,
407
+ * }: Route.LoaderArgs) {
408
+ * params.teamId;
409
+ * // ^ string
410
+ * }
411
+ */
412
+ params: Params;
413
+ /**
414
+ * This is the context passed in to your server adapter's getLoadContext() function.
415
+ * It's a way to bridge the gap between the adapter's request/response API with your React Router app.
416
+ * It is only applicable if you are using a custom server adapter.
417
+ */
418
+ context: Context;
419
+ }
420
+ /**
421
+ * Route middleware `next` function to call downstream handlers and then complete
422
+ * middlewares from the bottom-up
423
+ */
424
+ interface MiddlewareNextFunction<Result = unknown> {
425
+ (): Promise<Result>;
426
+ }
427
+ /**
428
+ * Route middleware function signature. Receives the same "data" arguments as a
429
+ * `loader`/`action` (`request`, `params`, `context`) as the first parameter and
430
+ * a `next` function as the second parameter which will call downstream handlers
431
+ * and then complete middlewares from the bottom-up
432
+ */
433
+ type MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<RouterContextProvider>>, next: MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
434
+ /**
435
+ * Arguments passed to loader functions
436
+ */
437
+ interface LoaderFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
438
+ }
439
+ /**
440
+ * Arguments passed to action functions
441
+ */
442
+ interface ActionFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
443
+ }
444
+ /**
445
+ * Loaders and actions can return anything
446
+ */
447
+ type DataFunctionValue = unknown;
448
+ type DataFunctionReturnValue = MaybePromise<DataFunctionValue>;
449
+ /**
450
+ * Route loader function signature
451
+ */
452
+ type LoaderFunction<Context = DefaultContext> = {
453
+ (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
454
+ } & {
455
+ hydrate?: boolean;
456
+ };
457
+ /**
458
+ * Route action function signature
459
+ */
460
+ interface ActionFunction<Context = DefaultContext> {
461
+ (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
462
+ }
463
+ /**
464
+ * Arguments passed to shouldRevalidate function
465
+ */
466
+ interface ShouldRevalidateFunctionArgs {
467
+ /** This is the url the navigation started from. You can compare it with `nextUrl` to decide if you need to revalidate this route's data. */
468
+ currentUrl: URL;
469
+ /** These are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the URL that can be compared to the `nextParams` to decide if you need to reload or not. Perhaps you're using only a partial piece of the param for data loading, you don't need to revalidate if a superfluous part of the param changed. */
470
+ currentParams: AgnosticDataRouteMatch["params"];
471
+ /** In the case of navigation, this the URL the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentUrl. */
472
+ nextUrl: URL;
473
+ /** In the case of navigation, these are the {@link https://reactrouter.com/start/framework/routing#dynamic-segments dynamic route params} from the next location the user is requesting. Some revalidations are not navigation, so it will simply be the same as currentParams. */
474
+ nextParams: AgnosticDataRouteMatch["params"];
475
+ /** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
476
+ formMethod?: Submission["formMethod"];
477
+ /** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
478
+ formAction?: Submission["formAction"];
479
+ /** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
480
+ formEncType?: Submission["formEncType"];
481
+ /** The form submission data when the form's encType is `text/plain` */
482
+ text?: Submission["text"];
483
+ /** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
484
+ formData?: Submission["formData"];
485
+ /** The form submission data when the form's encType is `application/json` */
486
+ json?: Submission["json"];
487
+ /** The status code of the action response */
488
+ actionStatus?: number;
489
+ /**
490
+ * When a submission causes the revalidation this will be the result of the action—either action data or an error if the action failed. It's common to include some information in the action result to instruct shouldRevalidate to revalidate or not.
491
+ *
492
+ * @example
493
+ * export async function action() {
494
+ * await saveSomeStuff();
495
+ * return { ok: true };
496
+ * }
497
+ *
498
+ * export function shouldRevalidate({
499
+ * actionResult,
500
+ * }) {
501
+ * if (actionResult?.ok) {
502
+ * return false;
503
+ * }
504
+ * return true;
505
+ * }
506
+ */
507
+ actionResult?: any;
508
+ /**
509
+ * By default, React Router doesn't call every loader all the time. There are reliable optimizations it can make by default. For example, only loaders with changing params are called. Consider navigating from the following URL to the one below it:
510
+ *
511
+ * /projects/123/tasks/abc
512
+ * /projects/123/tasks/def
513
+ * React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
514
+ *
515
+ * It's safest to always return defaultShouldRevalidate after you've done your specific optimizations that return false, otherwise your UI might get out of sync with your data on the server.
516
+ */
517
+ defaultShouldRevalidate: boolean;
518
+ }
519
+ /**
520
+ * Route shouldRevalidate function signature. This runs after any submission
521
+ * (navigation or fetcher), so we flatten the navigation/fetcher submission
522
+ * onto the arguments. It shouldn't matter whether it came from a navigation
523
+ * or a fetcher, what really matters is the URLs and the formData since loaders
524
+ * have to re-run based on the data models that were potentially mutated.
525
+ */
526
+ interface ShouldRevalidateFunction {
527
+ (args: ShouldRevalidateFunctionArgs): boolean;
528
+ }
529
+ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
530
+ /**
531
+ * @private
532
+ */
533
+ _lazyPromises?: {
534
+ middleware: Promise<void> | undefined;
535
+ handler: Promise<void> | undefined;
536
+ route: Promise<void> | undefined;
537
+ };
538
+ /**
539
+ * A boolean value indicating whether this route handler should be called in
540
+ * this pass.
541
+ *
542
+ * The `matches` array always includes _all_ matched routes even when only
543
+ * _some_ route handlers need to be called so that things like middleware can
544
+ * be implemented.
545
+ *
546
+ * `shouldLoad` is usually only interesting if you are skipping the route
547
+ * handler entirely and implementing custom handler logic - since it lets you
548
+ * determine if that custom logic should run for this route or not.
549
+ *
550
+ * For example:
551
+ * - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
552
+ * you'll get an array of three matches (`[parent, child, b]`), but only `b`
553
+ * will have `shouldLoad=true` because the data for `parent` and `child` is
554
+ * already loaded
555
+ * - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
556
+ * then only `a` will have `shouldLoad=true` for the action execution of
557
+ * `dataStrategy`
558
+ * - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
559
+ * `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
560
+ * revalidation, and all matches will have `shouldLoad=true` (assuming no
561
+ * custom `shouldRevalidate` implementations)
562
+ */
563
+ shouldLoad: boolean;
564
+ unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
565
+ unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
566
+ /**
567
+ * An async function that will resolve any `route.lazy` implementations and
568
+ * execute the route's handler (if necessary), returning a {@link DataStrategyResult}
569
+ *
570
+ * - Calling `match.resolve` does not mean you're calling the
571
+ * [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
572
+ * (the "handler") - `resolve` will only call the `handler` internally if
573
+ * needed _and_ if you don't pass your own `handlerOverride` function parameter
574
+ * - It is safe to call `match.resolve` for all matches, even if they have
575
+ * `shouldLoad=false`, and it will no-op if no loading is required
576
+ * - You should generally always call `match.resolve()` for `shouldLoad:true`
577
+ * routes to ensure that any `route.lazy` implementations are processed
578
+ * - See the examples below for how to implement custom handler execution via
579
+ * `match.resolve`
580
+ */
581
+ resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
582
+ }
583
+ interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
584
+ /**
585
+ * Matches for this route extended with Data strategy APIs
586
+ */
587
+ matches: DataStrategyMatch[];
588
+ runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
589
+ /**
590
+ * The key of the fetcher we are calling `dataStrategy` for, otherwise `null`
591
+ * for navigational executions
592
+ */
593
+ fetcherKey: string | null;
594
+ }
595
+ /**
596
+ * Result from a loader or action called via dataStrategy
597
+ */
598
+ interface DataStrategyResult {
599
+ type: "data" | "error";
600
+ result: unknown;
601
+ }
602
+ interface DataStrategyFunction<Context = DefaultContext> {
603
+ (args: DataStrategyFunctionArgs<Context>): Promise<Record<string, DataStrategyResult>>;
604
+ }
605
+ type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
606
+ signal: AbortSignal;
607
+ path: string;
608
+ matches: M[];
609
+ fetcherKey: string | undefined;
610
+ patch: (routeId: string | null, children: O[]) => void;
611
+ };
612
+ type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => MaybePromise<void>;
613
+ /**
614
+ * Function provided by the framework-aware layers to set any framework-specific
615
+ * properties from framework-agnostic properties
616
+ */
617
+ interface MapRoutePropertiesFunction {
618
+ (route: AgnosticRouteObject): {
619
+ hasErrorBoundary: boolean;
620
+ } & Record<string, any>;
621
+ }
622
+ /**
623
+ * Keys we cannot change from within a lazy object. We spread all other keys
624
+ * onto the route. Either they're meaningful to the router, or they'll get
625
+ * ignored.
626
+ */
627
+ type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
628
+ /**
629
+ * Keys we cannot change from within a lazy() function. We spread all other keys
630
+ * onto the route. Either they're meaningful to the router, or they'll get
631
+ * ignored.
632
+ */
633
+ type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "middleware";
634
+ /**
635
+ * lazy object to load route properties, which can add non-matching
636
+ * related properties to a route
637
+ */
638
+ type LazyRouteObject<R extends AgnosticRouteObject> = {
639
+ [K in keyof R as K extends UnsupportedLazyRouteObjectKey ? never : K]?: () => Promise<R[K] | null | undefined>;
640
+ };
641
+ /**
642
+ * lazy() function to load a route definition, which can add non-matching
643
+ * related properties to a route
644
+ */
645
+ interface LazyRouteFunction<R extends AgnosticRouteObject> {
646
+ (): Promise<Omit<R, UnsupportedLazyRouteFunctionKey> & Partial<Record<UnsupportedLazyRouteFunctionKey, never>>>;
647
+ }
648
+ type LazyRouteDefinition<R extends AgnosticRouteObject> = LazyRouteObject<R> | LazyRouteFunction<R>;
649
+ /**
650
+ * Base RouteObject with common props shared by all types of routes
651
+ */
652
+ type AgnosticBaseRouteObject = {
653
+ caseSensitive?: boolean;
654
+ path?: string;
655
+ id?: string;
656
+ middleware?: MiddlewareFunction[];
657
+ loader?: LoaderFunction | boolean;
658
+ action?: ActionFunction | boolean;
659
+ hasErrorBoundary?: boolean;
660
+ shouldRevalidate?: ShouldRevalidateFunction;
661
+ handle?: any;
662
+ lazy?: LazyRouteDefinition<AgnosticBaseRouteObject>;
663
+ };
664
+ /**
665
+ * Index routes must not have children
666
+ */
667
+ type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
668
+ children?: undefined;
669
+ index: true;
670
+ };
671
+ /**
672
+ * Non-index routes may have children, but cannot have index
673
+ */
674
+ type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
675
+ children?: AgnosticRouteObject[];
676
+ index?: false;
677
+ };
678
+ /**
679
+ * A route object represents a logical route, with (optionally) its child
680
+ * routes organized in a tree-like structure.
681
+ */
682
+ type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
683
+ type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
684
+ id: string;
685
+ };
686
+ type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
687
+ children?: AgnosticDataRouteObject[];
688
+ id: string;
689
+ };
690
+ /**
691
+ * A data route object, which is just a RouteObject with a required unique ID
692
+ */
693
+ type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
694
+ type RouteManifest<R = AgnosticDataRouteObject> = Record<string, R | undefined>;
695
+ type Regex_az = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
696
+ type Regez_AZ = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
697
+ type Regex_09 = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
698
+ type Regex_w = Regex_az | Regez_AZ | Regex_09 | "_";
699
+ type ParamChar = Regex_w | "-";
700
+ type RegexMatchPlus<CharPattern extends string, T extends string> = T extends `${infer First}${infer Rest}` ? First extends CharPattern ? RegexMatchPlus<CharPattern, Rest> extends never ? First : `${First}${RegexMatchPlus<CharPattern, Rest>}` : never : never;
701
+ type _PathParam<Path extends string> = Path extends `${infer L}/${infer R}` ? _PathParam<L> | _PathParam<R> : Path extends `:${infer Param}` ? Param extends `${infer Optional}?${string}` ? RegexMatchPlus<ParamChar, Optional> : RegexMatchPlus<ParamChar, Param> : never;
702
+ type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
703
+ type ParamParseKey<Segment extends string> = [
704
+ PathParam<Segment>
705
+ ] extends [never] ? string : PathParam<Segment>;
706
+ /**
707
+ * The parameters that were parsed from the URL path.
708
+ */
709
+ type Params<Key extends string = string> = {
710
+ readonly [key in Key]: string | undefined;
711
+ };
712
+ /**
713
+ * A RouteMatch contains info about how a route matched a URL.
714
+ */
715
+ interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
716
+ /**
717
+ * The names and values of dynamic parameters in the URL.
718
+ */
719
+ params: Params<ParamKey>;
720
+ /**
721
+ * The portion of the URL pathname that was matched.
722
+ */
723
+ pathname: string;
724
+ /**
725
+ * The portion of the URL pathname that was matched before child routes.
726
+ */
727
+ pathnameBase: string;
728
+ /**
729
+ * The route object that was used to match.
730
+ */
731
+ route: RouteObjectType;
732
+ }
733
+ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
734
+ }
735
+ /**
736
+ * Matches the given routes to a location and returns the match data.
737
+ *
738
+ * @example
739
+ * import { matchRoutes } from "react-router";
740
+ *
741
+ * let routes = [{
742
+ * path: "/",
743
+ * Component: Root,
744
+ * children: [{
745
+ * path: "dashboard",
746
+ * Component: Dashboard,
747
+ * }]
748
+ * }];
749
+ *
750
+ * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
751
+ *
752
+ * @public
753
+ * @category Utils
754
+ * @param routes The array of route objects to match against.
755
+ * @param locationArg The location to match against, either a string path or a
756
+ * partial {@link Location} object
757
+ * @param basename Optional base path to strip from the location before matching.
758
+ * Defaults to `/`.
759
+ * @returns An array of matched routes, or `null` if no matches were found.
760
+ */
761
+ declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
762
+ interface UIMatch<Data = unknown, Handle = unknown> {
763
+ id: string;
764
+ pathname: string;
765
+ /**
766
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
767
+ */
768
+ params: AgnosticRouteMatch["params"];
769
+ /**
770
+ * The return value from the matched route's loader or clientLoader. This might
771
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
772
+ * an error and we're currently displaying an `ErrorBoundary`.
773
+ *
774
+ * @deprecated Use `UIMatch.loaderData` instead
775
+ */
776
+ data: Data | undefined;
777
+ /**
778
+ * The return value from the matched route's loader or clientLoader. This might
779
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
780
+ * an error and we're currently displaying an `ErrorBoundary`.
781
+ */
782
+ loaderData: Data | undefined;
783
+ /**
784
+ * The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
785
+ * exported from the matched route module
786
+ */
787
+ handle: Handle;
788
+ }
789
+ /**
790
+ * Returns a path with params interpolated.
791
+ *
792
+ * @example
793
+ * import { generatePath } from "react-router";
794
+ *
795
+ * generatePath("/users/:id", { id: "123" }); // "/users/123"
796
+ *
797
+ * @public
798
+ * @category Utils
799
+ * @param originalPath The original path to generate.
800
+ * @param params The parameters to interpolate into the path.
801
+ * @returns The generated path with parameters interpolated.
802
+ */
803
+ declare function generatePath<Path extends string>(originalPath: Path, params?: {
804
+ [key in PathParam<Path>]: string | null;
805
+ }): string;
806
+ /**
807
+ * Used to match on some portion of a URL pathname.
808
+ */
809
+ interface PathPattern<Path extends string = string> {
810
+ /**
811
+ * A string to match against a URL pathname. May contain `:id`-style segments
812
+ * to indicate placeholders for dynamic parameters. It May also end with `/*`
813
+ * to indicate matching the rest of the URL pathname.
814
+ */
815
+ path: Path;
816
+ /**
817
+ * Should be `true` if the static portions of the `path` should be matched in
818
+ * the same case.
819
+ */
820
+ caseSensitive?: boolean;
821
+ /**
822
+ * Should be `true` if this pattern should match the entire URL pathname.
823
+ */
824
+ end?: boolean;
825
+ }
826
+ /**
827
+ * Contains info about how a {@link PathPattern} matched on a URL pathname.
828
+ */
829
+ interface PathMatch<ParamKey extends string = string> {
830
+ /**
831
+ * The names and values of dynamic parameters in the URL.
832
+ */
833
+ params: Params<ParamKey>;
834
+ /**
835
+ * The portion of the URL pathname that was matched.
836
+ */
837
+ pathname: string;
838
+ /**
839
+ * The portion of the URL pathname that was matched before child routes.
840
+ */
841
+ pathnameBase: string;
842
+ /**
843
+ * The pattern that was used to match.
844
+ */
845
+ pattern: PathPattern;
846
+ }
847
+ /**
848
+ * Performs pattern matching on a URL pathname and returns information about
849
+ * the match.
850
+ *
851
+ * @public
852
+ * @category Utils
853
+ * @param pattern The pattern to match against the URL pathname. This can be a
854
+ * string or a {@link PathPattern} object. If a string is provided, it will be
855
+ * treated as a pattern with `caseSensitive` set to `false` and `end` set to
856
+ * `true`.
857
+ * @param pathname The URL pathname to match against the pattern.
858
+ * @returns A path match object if the pattern matches the pathname,
859
+ * or `null` if it does not match.
860
+ */
861
+ declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
862
+ /**
863
+ * Returns a resolved {@link Path} object relative to the given pathname.
864
+ *
865
+ * @public
866
+ * @category Utils
867
+ * @param to The path to resolve, either a string or a partial {@link Path}
868
+ * object.
869
+ * @param fromPathname The pathname to resolve the path from. Defaults to `/`.
870
+ * @returns A {@link Path} object with the resolved pathname, search, and hash.
871
+ */
872
+ declare function resolvePath(to: To, fromPathname?: string): Path;
873
+ declare class DataWithResponseInit<D> {
874
+ type: string;
875
+ data: D;
876
+ init: ResponseInit | null;
877
+ constructor(data: D, init?: ResponseInit);
878
+ }
879
+ /**
880
+ * Create "responses" that contain `headers`/`status` without forcing
881
+ * serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
882
+ *
883
+ * @example
884
+ * import { data } from "react-router";
885
+ *
886
+ * export async function action({ request }: Route.ActionArgs) {
887
+ * let formData = await request.formData();
888
+ * let item = await createItem(formData);
889
+ * return data(item, {
890
+ * headers: { "X-Custom-Header": "value" }
891
+ * status: 201,
892
+ * });
893
+ * }
894
+ *
895
+ * @public
896
+ * @category Utils
897
+ * @mode framework
898
+ * @mode data
899
+ * @param data The data to be included in the response.
900
+ * @param init The status code or a `ResponseInit` object to be included in the
901
+ * response.
902
+ * @returns A {@link DataWithResponseInit} instance containing the data and
903
+ * response init.
904
+ */
905
+ declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
906
+ interface TrackedPromise extends Promise<any> {
907
+ _tracked?: boolean;
908
+ _data?: any;
909
+ _error?: any;
910
+ }
911
+ type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
912
+ /**
913
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
914
+ * Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
915
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
916
+ *
917
+ * @example
918
+ * import { redirect } from "react-router";
919
+ *
920
+ * export async function loader({ request }: Route.LoaderArgs) {
921
+ * if (!isLoggedIn(request))
922
+ * throw redirect("/login");
923
+ * }
924
+ *
925
+ * // ...
926
+ * }
927
+ *
928
+ * @public
929
+ * @category Utils
930
+ * @mode framework
931
+ * @mode data
932
+ * @param url The URL to redirect to.
933
+ * @param init The status code or a `ResponseInit` object to be included in the
934
+ * response.
935
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
936
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
937
+ * header.
938
+ */
939
+ declare const redirect: RedirectFunction;
940
+ /**
941
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
942
+ * that will force a document reload to the new location. Sets the status code
943
+ * and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
944
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
945
+ *
946
+ * ```tsx filename=routes/logout.tsx
947
+ * import { redirectDocument } from "react-router";
948
+ *
949
+ * import { destroySession } from "../sessions.server";
950
+ *
951
+ * export async function action({ request }: Route.ActionArgs) {
952
+ * let session = await getSession(request.headers.get("Cookie"));
953
+ * return redirectDocument("/", {
954
+ * headers: { "Set-Cookie": await destroySession(session) }
955
+ * });
956
+ * }
957
+ * ```
958
+ *
959
+ * @public
960
+ * @category Utils
961
+ * @mode framework
962
+ * @mode data
963
+ * @param url The URL to redirect to.
964
+ * @param init The status code or a `ResponseInit` object to be included in the
965
+ * response.
966
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
967
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
968
+ * header.
969
+ */
970
+ declare const redirectDocument: RedirectFunction;
971
+ /**
972
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
973
+ * that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
974
+ * instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
975
+ * for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
976
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
977
+ *
978
+ * @example
979
+ * import { replace } from "react-router";
980
+ *
981
+ * export async function loader() {
982
+ * return replace("/new-location");
983
+ * }
984
+ *
985
+ * @public
986
+ * @category Utils
987
+ * @mode framework
988
+ * @mode data
989
+ * @param url The URL to redirect to.
990
+ * @param init The status code or a `ResponseInit` object to be included in the
991
+ * response.
992
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
993
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
994
+ * header.
995
+ */
996
+ declare const replace: RedirectFunction;
997
+ type ErrorResponse = {
998
+ status: number;
999
+ statusText: string;
1000
+ data: any;
1001
+ };
1002
+ declare class ErrorResponseImpl implements ErrorResponse {
1003
+ status: number;
1004
+ statusText: string;
1005
+ data: any;
1006
+ private error?;
1007
+ private internal;
1008
+ constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
1009
+ }
1010
+ /**
1011
+ * Check if the given error is an {@link ErrorResponse} generated from a 4xx/5xx
1012
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1013
+ * thrown from an [`action`](../../start/framework/route-module#action)/[`loader`](../../start/framework/route-module#loader)
1014
+ *
1015
+ * @example
1016
+ * import { isRouteErrorResponse } from "react-router";
1017
+ *
1018
+ * export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
1019
+ * if (isRouteErrorResponse(error)) {
1020
+ * return (
1021
+ * <>
1022
+ * <p>Error: `${error.status}: ${error.statusText}`</p>
1023
+ * <p>{error.data}</p>
1024
+ * </>
1025
+ * );
1026
+ * }
1027
+ *
1028
+ * return (
1029
+ * <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
1030
+ * );
1031
+ * }
1032
+ *
1033
+ * @public
1034
+ * @category Utils
1035
+ * @mode framework
1036
+ * @mode data
1037
+ * @param error The error to check.
1038
+ * @returns `true` if the error is an {@link ErrorResponse}, `false` otherwise.
1039
+ *
1040
+ */
1041
+ declare function isRouteErrorResponse(error: any): error is ErrorResponse;
14
1042
 
15
1043
  /**
16
1044
  * A Router instance manages all navigation and data loading/mutations
@@ -296,7 +1324,6 @@ interface RouterInit {
296
1324
  history: History;
297
1325
  basename?: string;
298
1326
  getContext?: () => MaybePromise<RouterContextProvider>;
299
- unstable_instrumentations?: unstable_ClientInstrumentation[];
300
1327
  mapRouteProperties?: MapRoutePropertiesFunction;
301
1328
  future?: Partial<FutureConfig>;
302
1329
  hydrationRouteProperties?: string[];
@@ -570,7 +1597,6 @@ declare function createRouter(init: RouterInit): Router$1;
570
1597
  interface CreateStaticHandlerOptions {
571
1598
  basename?: string;
572
1599
  mapRouteProperties?: MapRoutePropertiesFunction;
573
- unstable_instrumentations?: Pick<unstable_ServerInstrumentation, "route">[];
574
1600
  future?: {};
575
1601
  }
576
1602
 
@@ -611,58 +1637,6 @@ interface MemoryRouterOpts {
611
1637
  * Index of `initialEntries` the application should initialize to
612
1638
  */
613
1639
  initialIndex?: number;
614
- /**
615
- * Array of instrumentation objects allowing you to instrument the router and
616
- * individual routes prior to router initialization (and on any subsequently
617
- * added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
618
- * mostly useful for observability such as wrapping navigations, fetches,
619
- * as well as route loaders/actions/middlewares with logging and/or performance
620
- * tracing.
621
- *
622
- * ```tsx
623
- * let router = createBrowserRouter(routes, {
624
- * unstable_instrumentations: [logging]
625
- * });
626
- *
627
- *
628
- * let logging = {
629
- * router({ instrument }) {
630
- * instrument({
631
- * navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
632
- * fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
633
- * });
634
- * },
635
- * route({ instrument, id }) {
636
- * instrument({
637
- * middleware: (impl, info) => logExecution(
638
- * `middleware ${info.request.url} (route ${id})`,
639
- * impl
640
- * ),
641
- * loader: (impl, info) => logExecution(
642
- * `loader ${info.request.url} (route ${id})`,
643
- * impl
644
- * ),
645
- * action: (impl, info) => logExecution(
646
- * `action ${info.request.url} (route ${id})`,
647
- * impl
648
- * ),
649
- * })
650
- * }
651
- * };
652
- *
653
- * async function logExecution(label: string, impl: () => Promise<void>) {
654
- * let start = performance.now();
655
- * console.log(`start ${label}`);
656
- * try {
657
- * await impl();
658
- * } finally {
659
- * let end = performance.now();
660
- * console.log(`end ${label} (${Math.round(end - start)}ms)`);
661
- * }
662
- * }
663
- * ```
664
- */
665
- unstable_instrumentations?: unstable_ClientInstrumentation[];
666
1640
  /**
667
1641
  * Override the default data strategy of loading in parallel.
668
1642
  * Only intended for advanced usage.
@@ -690,7 +1664,6 @@ interface MemoryRouterOpts {
690
1664
  * @param {MemoryRouterOpts.hydrationData} opts.hydrationData n/a
691
1665
  * @param {MemoryRouterOpts.initialEntries} opts.initialEntries n/a
692
1666
  * @param {MemoryRouterOpts.initialIndex} opts.initialIndex n/a
693
- * @param {MemoryRouterOpts.unstable_instrumentations} opts.unstable_instrumentations n/a
694
1667
  * @param {MemoryRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
695
1668
  * @returns An initialized {@link DataRouter} to pass to {@link RouterProvider | `<RouterProvider>`}
696
1669
  */
@@ -1703,6 +2676,16 @@ interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "
1703
2676
  }
1704
2677
  type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1705
2678
 
2679
+ /**
2680
+ * An object of unknown type for route loaders and actions provided by the
2681
+ * server's `getLoadContext()` function. This is defined as an empty interface
2682
+ * specifically so apps can leverage declaration merging to augment this type
2683
+ * globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
2684
+ */
2685
+ interface AppLoadContext {
2686
+ [key: string]: unknown;
2687
+ }
2688
+
1706
2689
  type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1707
2690
  [key: PropertyKey]: Serializable;
1708
2691
  } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
@@ -1778,11 +2761,6 @@ type ClientDataFunctionArgs<Params> = {
1778
2761
  * }
1779
2762
  **/
1780
2763
  params: Params;
1781
- /**
1782
- * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
1783
- * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
1784
- */
1785
- unstable_pattern: string;
1786
2764
  /**
1787
2765
  * When `future.v8_middleware` is not enabled, this is undefined.
1788
2766
  *
@@ -1811,11 +2789,6 @@ type ServerDataFunctionArgs<Params> = {
1811
2789
  * }
1812
2790
  **/
1813
2791
  params: Params;
1814
- /**
1815
- * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
1816
- * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
1817
- */
1818
- unstable_pattern: string;
1819
2792
  /**
1820
2793
  * Without `future.v8_middleware` enabled, this is the context passed in
1821
2794
  * to your server adapter's `getLoadContext` function. It's a way to bridge the
@@ -2062,4 +3035,4 @@ type RouteComponent = ComponentType<{}>;
2062
3035
  */
2063
3036
  type RouteHandle = unknown;
2064
3037
 
2065
- export { type RouteMatch as $, type AppLoadContext as A, type BlockerFunction as B, type ClientDataFunctionArgs as C, type DataRouteObject as D, type ErrorBoundaryType as E, type Func as F, type GetLoaderData as G, type HydrationState as H, type IndexRouteObject as I, type Fetcher as J, type NavigationStates as K, type LinkDescriptor as L, type MetaDescriptor as M, type Normalize as N, type RouterSubscriber as O, type Pretty as P, type RouterNavigateOptions as Q, type RouteModule$1 as R, type ServerDataFunctionArgs as S, type RouterFetchOptions as T, type RevalidationState as U, IDLE_NAVIGATION as V, IDLE_FETCHER as W, IDLE_BLOCKER as X, type DataRouteMatch as Y, type Navigator as Z, type PatchRoutesOnNavigationFunctionArgs as _, type ServerDataFrom as a, AwaitContextProvider as a0, type AwaitProps as a1, type IndexRouteProps as a2, type unstable_ClientOnErrorFunction as a3, type LayoutRouteProps as a4, type MemoryRouterOpts as a5, type MemoryRouterProps as a6, type NavigateProps as a7, type OutletProps as a8, type PathRouteProps as a9, FetchersContext as aA, LocationContext as aB, NavigationContext as aC, RouteContext as aD, ViewTransitionContext as aE, hydrationRouteProperties as aF, mapRouteProperties as aG, WithComponentProps as aH, withComponentProps as aI, WithHydrateFallbackProps as aJ, withHydrateFallbackProps as aK, WithErrorBoundaryProps as aL, withErrorBoundaryProps as aM, type ServerRouteModule as aN, type FutureConfig as aO, type CreateStaticHandlerOptions as aP, type RouteProps as aa, type RouterProps as ab, type RouterProviderProps as ac, type RoutesProps as ad, Await as ae, MemoryRouter as af, Navigate as ag, Outlet as ah, Route as ai, Router as aj, RouterProvider as ak, Routes as al, createMemoryRouter as am, createRoutesFromChildren as an, createRoutesFromElements as ao, renderMatches as ap, type ClientActionFunctionArgs as aq, type ClientLoaderFunctionArgs as ar, type HeadersArgs as as, type MetaArgs as at, type PageLinkDescriptor as au, type HtmlLinkDescriptor as av, type unstable_SerializesTo as aw, createRouter as ax, DataRouterContext as ay, DataRouterStateContext as az, type GetActionData as b, type Router$1 as c, type RouteModules as d, type NavigateOptions as e, type Blocker as f, type SerializeFrom as g, type RelativeRoutingType as h, type Navigation as i, type RouteObject as j, type RouteComponentType as k, type HydrateFallbackType as l, type MetaFunction as m, type LinksFunction as n, type NonIndexRouteObject as o, type Equal as p, type ClientActionFunction as q, type ClientLoaderFunction as r, type HeadersFunction as s, type RouterInit as t, type RouterState as u, type PatchRoutesOnNavigationFunction as v, type StaticHandler as w, type GetScrollPositionFunction as x, type GetScrollRestorationKeyFunction as y, type StaticHandlerContext as z };
3038
+ export { type PatchRoutesOnNavigationFunction as $, Action as A, type BlockerFunction as B, type ClientDataFunctionArgs as C, type DataStrategyResult as D, type ErrorBoundaryType as E, type Func as F, type GetLoaderData as G, type HydrationState as H, type InitialEntry as I, type AppLoadContext as J, RouterContextProvider as K, type LinkDescriptor as L, type MetaDescriptor as M, type Normalize as N, type MiddlewareEnabled as O, type Pretty as P, type Equal as Q, type RouteModule$1 as R, type ServerDataFunctionArgs as S, type To as T, type UIMatch as U, type ClientActionFunction as V, type ClientLoaderFunction as W, type HeadersFunction as X, type ShouldRevalidateFunction as Y, type RouterInit as Z, type RouterState as _, type Location as a, Route as a$, type DataRouteObject as a0, type StaticHandler as a1, type GetScrollPositionFunction as a2, type GetScrollRestorationKeyFunction as a3, type StaticHandlerContext as a4, type Fetcher as a5, type NavigationStates as a6, type RouterSubscriber as a7, type RouterNavigateOptions as a8, type RouterFetchOptions as a9, matchRoutes as aA, redirect as aB, redirectDocument as aC, replace as aD, resolvePath as aE, type DataRouteMatch as aF, type Navigator as aG, type PatchRoutesOnNavigationFunctionArgs as aH, type RouteMatch as aI, AwaitContextProvider as aJ, type AwaitProps as aK, type IndexRouteProps as aL, type unstable_ClientOnErrorFunction as aM, type LayoutRouteProps as aN, type MemoryRouterOpts as aO, type MemoryRouterProps as aP, type NavigateProps as aQ, type OutletProps as aR, type PathRouteProps as aS, type RouteProps as aT, type RouterProps as aU, type RouterProviderProps as aV, type RoutesProps as aW, Await as aX, MemoryRouter as aY, Navigate as aZ, Outlet as a_, type RevalidationState as aa, type ActionFunctionArgs as ab, type DataStrategyFunctionArgs as ac, type DataStrategyMatch as ad, DataWithResponseInit as ae, type ErrorResponse as af, type FormEncType as ag, type FormMethod as ah, type HTMLFormMethod as ai, type LazyRouteFunction as aj, type LoaderFunctionArgs as ak, type MiddlewareFunction as al, type PathParam as am, type RedirectFunction as an, type RouterContext as ao, type ShouldRevalidateFunctionArgs as ap, createContext as aq, createPath as ar, parsePath as as, IDLE_NAVIGATION as at, IDLE_FETCHER as au, IDLE_BLOCKER as av, data as aw, generatePath as ax, isRouteErrorResponse as ay, matchPath as az, type MiddlewareNextFunction as b, Router as b0, RouterProvider as b1, Routes as b2, createMemoryRouter as b3, createRoutesFromChildren as b4, createRoutesFromElements as b5, renderMatches as b6, type ClientActionFunctionArgs as b7, type ClientLoaderFunctionArgs as b8, type HeadersArgs as b9, type History as bA, type FutureConfig as bB, type CreateStaticHandlerOptions as bC, type MetaArgs as ba, type PageLinkDescriptor as bb, type HtmlLinkDescriptor as bc, type Future as bd, type unstable_SerializesTo as be, createBrowserHistory as bf, invariant as bg, createRouter as bh, ErrorResponseImpl as bi, DataRouterContext as bj, DataRouterStateContext as bk, FetchersContext as bl, LocationContext as bm, NavigationContext as bn, RouteContext as bo, ViewTransitionContext as bp, hydrationRouteProperties as bq, mapRouteProperties as br, WithComponentProps as bs, withComponentProps as bt, WithHydrateFallbackProps as bu, withHydrateFallbackProps as bv, WithErrorBoundaryProps as bw, withErrorBoundaryProps as bx, type RouteManifest as by, type ServerRouteModule as bz, type ServerDataFrom as c, type GetActionData as d, type Router$1 as e, type RouteModules as f, type DataStrategyFunction as g, type NavigateOptions as h, type Blocker as i, type SerializeFrom as j, type RelativeRoutingType as k, type ParamParseKey as l, type Path as m, type PathPattern as n, type PathMatch as o, type Navigation as p, type Params as q, type RouteObject as r, type IndexRouteObject as s, type RouteComponentType as t, type HydrateFallbackType as u, type LoaderFunction as v, type ActionFunction as w, type MetaFunction as x, type LinksFunction as y, type NonIndexRouteObject as z };