react-router 7.13.1 → 7.13.2

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 (76) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/{production/browser-DzsJABDQ.d.mts → development/browser-Bfn3xw9E.d.ts} +2 -1
  3. package/dist/development/{browser-DzsJABDQ.d.mts → browser-Di6-vSl-.d.mts} +2 -1
  4. package/dist/development/{chunk-XOLAXE2Z.js → chunk-GO74ODU3.js} +190 -111
  5. package/dist/{production/chunk-B5UMK6O7.js → development/chunk-HPFFRPKK.js} +100 -99
  6. package/dist/development/{chunk-KSEWV2VO.js → chunk-LLP6DRWX.js} +7 -7
  7. package/dist/{production/chunk-TXB4YXR2.mjs → development/chunk-UALY5CBT.mjs} +83 -49
  8. package/dist/development/{chunk-LFPYN7LY.mjs → chunk-UVKPFVEO.mjs} +124 -44
  9. package/dist/development/context-phCt_zmH.d.mts +1713 -0
  10. package/dist/development/dom-export.d.mts +3 -2
  11. package/dist/development/dom-export.d.ts +3 -2
  12. package/dist/development/dom-export.js +45 -29
  13. package/dist/development/dom-export.mjs +21 -5
  14. package/dist/development/{index-react-server-client-C4tCIird.d.ts → index-react-server-client-BcrVT7Dd.d.mts} +4 -2
  15. package/dist/{production/index-react-server-client-EzWJGpN_.d.mts → development/index-react-server-client-CCwMoQIT.d.ts} +1067 -10
  16. package/dist/development/index-react-server-client.d.mts +3 -2
  17. package/dist/development/index-react-server-client.d.ts +3 -2
  18. package/dist/development/index-react-server-client.js +4 -4
  19. package/dist/development/index-react-server-client.mjs +2 -2
  20. package/dist/development/index-react-server.d.mts +293 -246
  21. package/dist/development/index-react-server.d.ts +293 -246
  22. package/dist/development/index-react-server.js +121 -43
  23. package/dist/development/index-react-server.mjs +121 -43
  24. package/dist/development/index.d.mts +15 -13
  25. package/dist/development/index.d.ts +15 -13
  26. package/dist/development/index.js +176 -142
  27. package/dist/development/index.mjs +3 -3
  28. package/dist/development/instrumentation-BYr6ff5D.d.ts +657 -0
  29. package/dist/development/lib/types/internal.d.mts +2 -2
  30. package/dist/development/lib/types/internal.d.ts +2 -2
  31. package/dist/development/lib/types/internal.js +1 -1
  32. package/dist/development/lib/types/internal.mjs +1 -1
  33. package/dist/development/{register-CBoanF80.d.ts → register-CTxsJBKQ.d.mts} +1 -1
  34. package/dist/development/{register-cRYJ3CjG.d.mts → register-CkcGwv27.d.ts} +1 -1
  35. package/dist/development/routeModules-BRrCYrSL.d.mts +1693 -0
  36. package/dist/development/routeModules-CA7kSxJJ.d.ts +1693 -0
  37. package/dist/production/{browser-sPQ7eaK4.d.ts → browser-Bfn3xw9E.d.ts} +2 -1
  38. package/dist/{development/browser-sPQ7eaK4.d.ts → production/browser-Di6-vSl-.d.mts} +2 -1
  39. package/dist/production/{chunk-RJCJ3EYF.mjs → chunk-2BDJPJTA.mjs} +124 -44
  40. package/dist/production/{chunk-ZJMCM6KT.js → chunk-CAFVLUDY.js} +7 -7
  41. package/dist/production/{chunk-772H4TVR.js → chunk-LKUVSIBA.js} +190 -111
  42. package/dist/{development/chunk-JPUPSTYD.mjs → production/chunk-PY35PE22.mjs} +83 -49
  43. package/dist/{development/chunk-2YMDXNOJ.js → production/chunk-XAAX7KIK.js} +100 -99
  44. package/dist/production/context-phCt_zmH.d.mts +1713 -0
  45. package/dist/production/dom-export.d.mts +3 -2
  46. package/dist/production/dom-export.d.ts +3 -2
  47. package/dist/production/dom-export.js +45 -29
  48. package/dist/production/dom-export.mjs +21 -5
  49. package/dist/{development/index-react-server-client-EzWJGpN_.d.mts → production/index-react-server-client-BcrVT7Dd.d.mts} +4 -2
  50. package/dist/production/{index-react-server-client-C4tCIird.d.ts → index-react-server-client-CCwMoQIT.d.ts} +1067 -10
  51. package/dist/production/index-react-server-client.d.mts +3 -2
  52. package/dist/production/index-react-server-client.d.ts +3 -2
  53. package/dist/production/index-react-server-client.js +4 -4
  54. package/dist/production/index-react-server-client.mjs +2 -2
  55. package/dist/production/index-react-server.d.mts +293 -246
  56. package/dist/production/index-react-server.d.ts +293 -246
  57. package/dist/production/index-react-server.js +121 -43
  58. package/dist/production/index-react-server.mjs +121 -43
  59. package/dist/production/index.d.mts +15 -13
  60. package/dist/production/index.d.ts +15 -13
  61. package/dist/production/index.js +176 -142
  62. package/dist/production/index.mjs +3 -3
  63. package/dist/production/instrumentation-BYr6ff5D.d.ts +657 -0
  64. package/dist/production/lib/types/internal.d.mts +2 -2
  65. package/dist/production/lib/types/internal.d.ts +2 -2
  66. package/dist/production/lib/types/internal.js +1 -1
  67. package/dist/production/lib/types/internal.mjs +1 -1
  68. package/dist/production/{register-CBoanF80.d.ts → register-CTxsJBKQ.d.mts} +1 -1
  69. package/dist/production/{register-cRYJ3CjG.d.mts → register-CkcGwv27.d.ts} +1 -1
  70. package/dist/production/routeModules-BRrCYrSL.d.mts +1693 -0
  71. package/dist/production/routeModules-CA7kSxJJ.d.ts +1693 -0
  72. package/package.json +1 -1
  73. package/dist/development/instrumentation--6Pioq_G.d.ts +0 -3344
  74. package/dist/development/router-cLsU7kHk.d.mts +0 -3344
  75. package/dist/production/instrumentation--6Pioq_G.d.ts +0 -3344
  76. package/dist/production/router-cLsU7kHk.d.mts +0 -3344
@@ -0,0 +1,1693 @@
1
+ import * as React from 'react';
2
+ import { ComponentType, ReactElement } from 'react';
3
+
4
+ /**
5
+ * Actions represent the type of change to a location value.
6
+ */
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;
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
+ * The masked location displayed in the URL bar, which differs from the URL the
63
+ * router is operating on
64
+ */
65
+ unstable_mask: Path | undefined;
66
+ }
67
+ /**
68
+ * A change to the current location.
69
+ */
70
+ interface Update {
71
+ /**
72
+ * The action that triggered the change.
73
+ */
74
+ action: Action;
75
+ /**
76
+ * The new location.
77
+ */
78
+ location: Location;
79
+ /**
80
+ * The delta between this location and the former location in the history stack
81
+ */
82
+ delta: number | null;
83
+ }
84
+ /**
85
+ * A function that receives notifications about location changes.
86
+ */
87
+ interface Listener {
88
+ (update: Update): void;
89
+ }
90
+ /**
91
+ * Describes a location that is the destination of some navigation used in
92
+ * {@link Link}, {@link useNavigate}, etc.
93
+ */
94
+ type To = string | Partial<Path>;
95
+ /**
96
+ * A history is an interface to the navigation stack. The history serves as the
97
+ * source of truth for the current location, as well as provides a set of
98
+ * methods that may be used to change it.
99
+ *
100
+ * It is similar to the DOM's `window.history` object, but with a smaller, more
101
+ * focused API.
102
+ */
103
+ interface History {
104
+ /**
105
+ * The last action that modified the current location. This will always be
106
+ * Action.Pop when a history instance is first created. This value is mutable.
107
+ */
108
+ readonly action: Action;
109
+ /**
110
+ * The current location. This value is mutable.
111
+ */
112
+ readonly location: Location;
113
+ /**
114
+ * Returns a valid href for the given `to` value that may be used as
115
+ * the value of an <a href> attribute.
116
+ *
117
+ * @param to - The destination URL
118
+ */
119
+ createHref(to: To): string;
120
+ /**
121
+ * Returns a URL for the given `to` value
122
+ *
123
+ * @param to - The destination URL
124
+ */
125
+ createURL(to: To): URL;
126
+ /**
127
+ * Encode a location the same way window.history would do (no-op for memory
128
+ * history) so we ensure our PUSH/REPLACE navigations for data routers
129
+ * behave the same as POP
130
+ *
131
+ * @param to Unencoded path
132
+ */
133
+ encodeLocation(to: To): Path;
134
+ /**
135
+ * Pushes a new location onto the history stack, increasing its length by one.
136
+ * If there were any entries in the stack after the current one, they are
137
+ * lost.
138
+ *
139
+ * @param to - The new URL
140
+ * @param state - Data to associate with the new location
141
+ */
142
+ push(to: To, state?: any): void;
143
+ /**
144
+ * Replaces the current location in the history stack with a new one. The
145
+ * location that was replaced will no longer be available.
146
+ *
147
+ * @param to - The new URL
148
+ * @param state - Data to associate with the new location
149
+ */
150
+ replace(to: To, state?: any): void;
151
+ /**
152
+ * Navigates `n` entries backward/forward in the history stack relative to the
153
+ * current index. For example, a "back" navigation would use go(-1).
154
+ *
155
+ * @param delta - The delta in the stack index
156
+ */
157
+ go(delta: number): void;
158
+ /**
159
+ * Sets up a listener that will be called whenever the current location
160
+ * changes.
161
+ *
162
+ * @param listener - A function that will be called when the location changes
163
+ * @returns unlisten - A function that may be used to stop listening
164
+ */
165
+ listen(listener: Listener): () => void;
166
+ }
167
+ /**
168
+ * A user-supplied object that describes a location. Used when providing
169
+ * entries to `createMemoryHistory` via its `initialEntries` option.
170
+ */
171
+ type InitialEntry = string | Partial<Location>;
172
+ type MemoryHistoryOptions = {
173
+ initialEntries?: InitialEntry[];
174
+ initialIndex?: number;
175
+ v5Compat?: boolean;
176
+ };
177
+ /**
178
+ * A memory history stores locations in memory. This is useful in stateful
179
+ * environments where there is no web browser, such as node tests or React
180
+ * Native.
181
+ */
182
+ interface MemoryHistory extends History {
183
+ /**
184
+ * The current index in the history stack.
185
+ */
186
+ readonly index: number;
187
+ }
188
+ /**
189
+ * Memory history stores the current location in memory. It is designed for use
190
+ * in stateful non-browser environments like tests and React Native.
191
+ */
192
+ declare function createMemoryHistory(options?: MemoryHistoryOptions): MemoryHistory;
193
+ /**
194
+ * A browser history stores the current location in regular URLs in a web
195
+ * browser environment. This is the standard for most web apps and provides the
196
+ * cleanest URLs the browser's address bar.
197
+ *
198
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
199
+ */
200
+ interface BrowserHistory extends UrlHistory {
201
+ }
202
+ type BrowserHistoryOptions = UrlHistoryOptions;
203
+ /**
204
+ * Browser history stores the location in regular URLs. This is the standard for
205
+ * most web apps, but it requires some configuration on the server to ensure you
206
+ * serve the same app at multiple URLs.
207
+ *
208
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
209
+ */
210
+ declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
211
+ /**
212
+ * A hash history stores the current location in the fragment identifier portion
213
+ * of the URL in a web browser environment.
214
+ *
215
+ * This is ideal for apps that do not control the server for some reason
216
+ * (because the fragment identifier is never sent to the server), including some
217
+ * shared hosting environments that do not provide fine-grained controls over
218
+ * which pages are served at which URLs.
219
+ *
220
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory
221
+ */
222
+ interface HashHistory extends UrlHistory {
223
+ }
224
+ type HashHistoryOptions = UrlHistoryOptions;
225
+ /**
226
+ * Hash history stores the location in window.location.hash. This makes it ideal
227
+ * for situations where you don't want to send the location to the server for
228
+ * some reason, either because you do cannot configure it or the URL space is
229
+ * reserved for something else.
230
+ *
231
+ * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
232
+ */
233
+ declare function createHashHistory(options?: HashHistoryOptions): HashHistory;
234
+ /**
235
+ * @private
236
+ */
237
+ declare function invariant(value: boolean, message?: string): asserts value;
238
+ declare function invariant<T>(value: T | null | undefined, message?: string): asserts value is T;
239
+ /**
240
+ * Creates a string URL path from the given pathname, search, and hash components.
241
+ *
242
+ * @category Utils
243
+ */
244
+ declare function createPath({ pathname, search, hash, }: Partial<Path>): string;
245
+ /**
246
+ * Parses a string URL path into its separate pathname, search, and hash components.
247
+ *
248
+ * @category Utils
249
+ */
250
+ declare function parsePath(path: string): Partial<Path>;
251
+ interface UrlHistory extends History {
252
+ }
253
+ type UrlHistoryOptions = {
254
+ window?: Window;
255
+ v5Compat?: boolean;
256
+ };
257
+
258
+ /**
259
+ * An augmentable interface users can modify in their app-code to opt into
260
+ * future-flag-specific types
261
+ */
262
+ interface Future {
263
+ }
264
+ type MiddlewareEnabled = Future extends {
265
+ v8_middleware: infer T extends boolean;
266
+ } ? T : false;
267
+
268
+ type MaybePromise<T> = T | Promise<T>;
269
+ /**
270
+ * Map of routeId -> data returned from a loader/action/error
271
+ */
272
+ interface RouteData {
273
+ [routeId: string]: any;
274
+ }
275
+ type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
276
+ type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
277
+ /**
278
+ * Users can specify either lowercase or uppercase form methods on `<Form>`,
279
+ * useSubmit(), `<fetcher.Form>`, etc.
280
+ */
281
+ type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
282
+ /**
283
+ * Active navigation/fetcher form methods are exposed in uppercase on the
284
+ * RouterState. This is to align with the normalization done via fetch().
285
+ */
286
+ type FormMethod = UpperCaseFormMethod;
287
+ type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
288
+ type JsonObject = {
289
+ [Key in string]: JsonValue;
290
+ } & {
291
+ [Key in string]?: JsonValue | undefined;
292
+ };
293
+ type JsonArray = JsonValue[] | readonly JsonValue[];
294
+ type JsonPrimitive = string | number | boolean | null;
295
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
296
+ /**
297
+ * @private
298
+ * Internal interface to pass around for action submissions, not intended for
299
+ * external consumption
300
+ */
301
+ type Submission = {
302
+ formMethod: FormMethod;
303
+ formAction: string;
304
+ formEncType: FormEncType;
305
+ formData: FormData;
306
+ json: undefined;
307
+ text: undefined;
308
+ } | {
309
+ formMethod: FormMethod;
310
+ formAction: string;
311
+ formEncType: FormEncType;
312
+ formData: undefined;
313
+ json: JsonValue;
314
+ text: undefined;
315
+ } | {
316
+ formMethod: FormMethod;
317
+ formAction: string;
318
+ formEncType: FormEncType;
319
+ formData: undefined;
320
+ json: undefined;
321
+ text: string;
322
+ };
323
+ /**
324
+ * A context instance used as the key for the `get`/`set` methods of a
325
+ * {@link RouterContextProvider}. Accepts an optional default
326
+ * value to be returned if no value has been set.
327
+ */
328
+ interface RouterContext<T = unknown> {
329
+ defaultValue?: T;
330
+ }
331
+ /**
332
+ * Creates a type-safe {@link RouterContext} object that can be used to
333
+ * store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
334
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
335
+ * Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
336
+ * but specifically designed for React Router's request/response lifecycle.
337
+ *
338
+ * If a `defaultValue` is provided, it will be returned from `context.get()`
339
+ * when no value has been set for the context. Otherwise, reading this context
340
+ * when no value has been set will throw an error.
341
+ *
342
+ * ```tsx filename=app/context.ts
343
+ * import { createContext } from "react-router";
344
+ *
345
+ * // Create a context for user data
346
+ * export const userContext =
347
+ * createContext<User | null>(null);
348
+ * ```
349
+ *
350
+ * ```tsx filename=app/middleware/auth.ts
351
+ * import { getUserFromSession } from "~/auth.server";
352
+ * import { userContext } from "~/context";
353
+ *
354
+ * export const authMiddleware = async ({
355
+ * context,
356
+ * request,
357
+ * }) => {
358
+ * const user = await getUserFromSession(request);
359
+ * context.set(userContext, user);
360
+ * };
361
+ * ```
362
+ *
363
+ * ```tsx filename=app/routes/profile.tsx
364
+ * import { userContext } from "~/context";
365
+ *
366
+ * export async function loader({
367
+ * context,
368
+ * }: Route.LoaderArgs) {
369
+ * const user = context.get(userContext);
370
+ *
371
+ * if (!user) {
372
+ * throw new Response("Unauthorized", { status: 401 });
373
+ * }
374
+ *
375
+ * return { user };
376
+ * }
377
+ * ```
378
+ *
379
+ * @public
380
+ * @category Utils
381
+ * @mode framework
382
+ * @mode data
383
+ * @param defaultValue An optional default value for the context. This value
384
+ * will be returned if no value has been set for this context.
385
+ * @returns A {@link RouterContext} object that can be used with
386
+ * `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
387
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
388
+ */
389
+ declare function createContext<T>(defaultValue?: T): RouterContext<T>;
390
+ /**
391
+ * Provides methods for writing/reading values in application context in a
392
+ * type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
393
+ *
394
+ * @example
395
+ * import {
396
+ * createContext,
397
+ * RouterContextProvider
398
+ * } from "react-router";
399
+ *
400
+ * const userContext = createContext<User | null>(null);
401
+ * const contextProvider = new RouterContextProvider();
402
+ * contextProvider.set(userContext, getUser());
403
+ * // ^ Type-safe
404
+ * const user = contextProvider.get(userContext);
405
+ * // ^ User
406
+ *
407
+ * @public
408
+ * @category Utils
409
+ * @mode framework
410
+ * @mode data
411
+ */
412
+ declare class RouterContextProvider {
413
+ #private;
414
+ /**
415
+ * Create a new `RouterContextProvider` instance
416
+ * @param init An optional initial context map to populate the provider with
417
+ */
418
+ constructor(init?: Map<RouterContext, unknown>);
419
+ /**
420
+ * Access a value from the context. If no value has been set for the context,
421
+ * it will return the context's `defaultValue` if provided, or throw an error
422
+ * if no `defaultValue` was set.
423
+ * @param context The context to get the value for
424
+ * @returns The value for the context, or the context's `defaultValue` if no
425
+ * value was set
426
+ */
427
+ get<T>(context: RouterContext<T>): T;
428
+ /**
429
+ * Set a value for the context. If the context already has a value set, this
430
+ * will overwrite it.
431
+ *
432
+ * @param context The context to set the value for
433
+ * @param value The value to set for the context
434
+ * @returns {void}
435
+ */
436
+ set<C extends RouterContext>(context: C, value: C extends RouterContext<infer T> ? T : never): void;
437
+ }
438
+ type DefaultContext = MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : any;
439
+ /**
440
+ * @private
441
+ * Arguments passed to route loader/action functions. Same for now but we keep
442
+ * this as a private implementation detail in case they diverge in the future.
443
+ */
444
+ interface DataFunctionArgs<Context> {
445
+ /** 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. */
446
+ request: Request;
447
+ /**
448
+ * A URL instance representing the application location being navigated to or fetched.
449
+ * Without `future.unstable_passThroughRequests` enabled, this matches `request.url`.
450
+ * With `future.unstable_passThroughRequests` enabled, this is a normalized
451
+ * URL with React-Router-specific implementation details removed (`.data`
452
+ * suffixes, `index`/`_routes` search params).
453
+ * The URL includes the origin from the request for convenience.
454
+ */
455
+ unstable_url: URL;
456
+ /**
457
+ * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
458
+ * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
459
+ */
460
+ unstable_pattern: string;
461
+ /**
462
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
463
+ * @example
464
+ * // app/routes.ts
465
+ * route("teams/:teamId", "./team.tsx"),
466
+ *
467
+ * // app/team.tsx
468
+ * export function loader({
469
+ * params,
470
+ * }: Route.LoaderArgs) {
471
+ * params.teamId;
472
+ * // ^ string
473
+ * }
474
+ */
475
+ params: Params;
476
+ /**
477
+ * This is the context passed in to your server adapter's getLoadContext() function.
478
+ * It's a way to bridge the gap between the adapter's request/response API with your React Router app.
479
+ * It is only applicable if you are using a custom server adapter.
480
+ */
481
+ context: Context;
482
+ }
483
+ /**
484
+ * Route middleware `next` function to call downstream handlers and then complete
485
+ * middlewares from the bottom-up
486
+ */
487
+ interface MiddlewareNextFunction<Result = unknown> {
488
+ (): Promise<Result>;
489
+ }
490
+ /**
491
+ * Route middleware function signature. Receives the same "data" arguments as a
492
+ * `loader`/`action` (`request`, `params`, `context`) as the first parameter and
493
+ * a `next` function as the second parameter which will call downstream handlers
494
+ * and then complete middlewares from the bottom-up
495
+ */
496
+ type MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<RouterContextProvider>>, next: MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
497
+ /**
498
+ * Arguments passed to loader functions
499
+ */
500
+ interface LoaderFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
501
+ }
502
+ /**
503
+ * Arguments passed to action functions
504
+ */
505
+ interface ActionFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
506
+ }
507
+ /**
508
+ * Loaders and actions can return anything
509
+ */
510
+ type DataFunctionValue = unknown;
511
+ type DataFunctionReturnValue = MaybePromise<DataFunctionValue>;
512
+ /**
513
+ * Route loader function signature
514
+ */
515
+ type LoaderFunction<Context = DefaultContext> = {
516
+ (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
517
+ } & {
518
+ hydrate?: boolean;
519
+ };
520
+ /**
521
+ * Route action function signature
522
+ */
523
+ interface ActionFunction<Context = DefaultContext> {
524
+ (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
525
+ }
526
+ /**
527
+ * Arguments passed to shouldRevalidate function
528
+ */
529
+ interface ShouldRevalidateFunctionArgs {
530
+ /** 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. */
531
+ currentUrl: URL;
532
+ /** 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. */
533
+ currentParams: DataRouteMatch["params"];
534
+ /** 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. */
535
+ nextUrl: URL;
536
+ /** 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. */
537
+ nextParams: DataRouteMatch["params"];
538
+ /** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
539
+ formMethod?: Submission["formMethod"];
540
+ /** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
541
+ formAction?: Submission["formAction"];
542
+ /** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
543
+ formEncType?: Submission["formEncType"];
544
+ /** The form submission data when the form's encType is `text/plain` */
545
+ text?: Submission["text"];
546
+ /** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
547
+ formData?: Submission["formData"];
548
+ /** The form submission data when the form's encType is `application/json` */
549
+ json?: Submission["json"];
550
+ /** The status code of the action response */
551
+ actionStatus?: number;
552
+ /**
553
+ * 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.
554
+ *
555
+ * @example
556
+ * export async function action() {
557
+ * await saveSomeStuff();
558
+ * return { ok: true };
559
+ * }
560
+ *
561
+ * export function shouldRevalidate({
562
+ * actionResult,
563
+ * }) {
564
+ * if (actionResult?.ok) {
565
+ * return false;
566
+ * }
567
+ * return true;
568
+ * }
569
+ */
570
+ actionResult?: any;
571
+ /**
572
+ * 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:
573
+ *
574
+ * /projects/123/tasks/abc
575
+ * /projects/123/tasks/def
576
+ * React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
577
+ *
578
+ * 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.
579
+ */
580
+ defaultShouldRevalidate: boolean;
581
+ }
582
+ /**
583
+ * Route shouldRevalidate function signature. This runs after any submission
584
+ * (navigation or fetcher), so we flatten the navigation/fetcher submission
585
+ * onto the arguments. It shouldn't matter whether it came from a navigation
586
+ * or a fetcher, what really matters is the URLs and the formData since loaders
587
+ * have to re-run based on the data models that were potentially mutated.
588
+ */
589
+ interface ShouldRevalidateFunction {
590
+ (args: ShouldRevalidateFunctionArgs): boolean;
591
+ }
592
+ interface DataStrategyMatch extends RouteMatch<string, DataRouteObject> {
593
+ /**
594
+ * @private
595
+ */
596
+ _lazyPromises?: {
597
+ middleware: Promise<void> | undefined;
598
+ handler: Promise<void> | undefined;
599
+ route: Promise<void> | undefined;
600
+ };
601
+ /**
602
+ * @deprecated Deprecated in favor of `shouldCallHandler`
603
+ *
604
+ * A boolean value indicating whether this route handler should be called in
605
+ * this pass.
606
+ *
607
+ * The `matches` array always includes _all_ matched routes even when only
608
+ * _some_ route handlers need to be called so that things like middleware can
609
+ * be implemented.
610
+ *
611
+ * `shouldLoad` is usually only interesting if you are skipping the route
612
+ * handler entirely and implementing custom handler logic - since it lets you
613
+ * determine if that custom logic should run for this route or not.
614
+ *
615
+ * For example:
616
+ * - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
617
+ * you'll get an array of three matches (`[parent, child, b]`), but only `b`
618
+ * will have `shouldLoad=true` because the data for `parent` and `child` is
619
+ * already loaded
620
+ * - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
621
+ * then only `a` will have `shouldLoad=true` for the action execution of
622
+ * `dataStrategy`
623
+ * - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
624
+ * `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
625
+ * revalidation, and all matches will have `shouldLoad=true` (assuming no
626
+ * custom `shouldRevalidate` implementations)
627
+ */
628
+ shouldLoad: boolean;
629
+ /**
630
+ * Arguments passed to the `shouldRevalidate` function for this `loader` execution.
631
+ * Will be `null` if this is not a revalidating loader {@link DataStrategyMatch}.
632
+ */
633
+ shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
634
+ /**
635
+ * Determine if this route's handler should be called during this `dataStrategy`
636
+ * execution. Calling it with no arguments will leverage the default revalidation
637
+ * behavior. You can pass your own `defaultShouldRevalidate` value if you wish
638
+ * to change the default revalidation behavior with your `dataStrategy`.
639
+ *
640
+ * @param defaultShouldRevalidate `defaultShouldRevalidate` override value (optional)
641
+ */
642
+ shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
643
+ /**
644
+ * An async function that will resolve any `route.lazy` implementations and
645
+ * execute the route's handler (if necessary), returning a {@link DataStrategyResult}
646
+ *
647
+ * - Calling `match.resolve` does not mean you're calling the
648
+ * [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
649
+ * (the "handler") - `resolve` will only call the `handler` internally if
650
+ * needed _and_ if you don't pass your own `handlerOverride` function parameter
651
+ * - It is safe to call `match.resolve` for all matches, even if they have
652
+ * `shouldLoad=false`, and it will no-op if no loading is required
653
+ * - You should generally always call `match.resolve()` for `shouldLoad:true`
654
+ * routes to ensure that any `route.lazy` implementations are processed
655
+ * - See the examples below for how to implement custom handler execution via
656
+ * `match.resolve`
657
+ */
658
+ resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
659
+ }
660
+ interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
661
+ /**
662
+ * Matches for this route extended with Data strategy APIs
663
+ */
664
+ matches: DataStrategyMatch[];
665
+ runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
666
+ /**
667
+ * The key of the fetcher we are calling `dataStrategy` for, otherwise `null`
668
+ * for navigational executions
669
+ */
670
+ fetcherKey: string | null;
671
+ }
672
+ /**
673
+ * Result from a loader or action called via dataStrategy
674
+ */
675
+ interface DataStrategyResult {
676
+ type: "data" | "error";
677
+ result: unknown;
678
+ }
679
+ interface DataStrategyFunction<Context = DefaultContext> {
680
+ (args: DataStrategyFunctionArgs<Context>): Promise<Record<string, DataStrategyResult>>;
681
+ }
682
+ type PatchRoutesOnNavigationFunctionArgs = {
683
+ signal: AbortSignal;
684
+ path: string;
685
+ matches: RouteMatch[];
686
+ fetcherKey: string | undefined;
687
+ patch: (routeId: string | null, children: RouteObject[]) => void;
688
+ };
689
+ type PatchRoutesOnNavigationFunction = (opts: PatchRoutesOnNavigationFunctionArgs) => MaybePromise<void>;
690
+ /**
691
+ * Function provided to set route-specific properties from route objects
692
+ */
693
+ interface MapRoutePropertiesFunction {
694
+ (route: DataRouteObject): {
695
+ hasErrorBoundary: boolean;
696
+ } & Record<string, any>;
697
+ }
698
+ /**
699
+ * Keys we cannot change from within a lazy object. We spread all other keys
700
+ * onto the route. Either they're meaningful to the router, or they'll get
701
+ * ignored.
702
+ */
703
+ type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
704
+ /**
705
+ * Keys we cannot change from within a lazy() function. We spread all other keys
706
+ * onto the route. Either they're meaningful to the router, or they'll get
707
+ * ignored.
708
+ */
709
+ type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "middleware";
710
+ /**
711
+ * lazy object to load route properties, which can add non-matching
712
+ * related properties to a route
713
+ */
714
+ type LazyRouteObject<R extends RouteObject> = {
715
+ [K in keyof R as K extends UnsupportedLazyRouteObjectKey ? never : K]?: () => Promise<R[K] | null | undefined>;
716
+ };
717
+ /**
718
+ * lazy() function to load a route definition, which can add non-matching
719
+ * related properties to a route
720
+ */
721
+ interface LazyRouteFunction<R extends RouteObject> {
722
+ (): Promise<Omit<R, UnsupportedLazyRouteFunctionKey> & Partial<Record<UnsupportedLazyRouteFunctionKey, never>>>;
723
+ }
724
+ type LazyRouteDefinition<R extends RouteObject> = LazyRouteObject<R> | LazyRouteFunction<R>;
725
+ /**
726
+ * Base RouteObject with common props shared by all types of routes
727
+ * @internal
728
+ */
729
+ type BaseRouteObject = {
730
+ /**
731
+ * Whether the path should be case-sensitive. Defaults to `false`.
732
+ */
733
+ caseSensitive?: boolean;
734
+ /**
735
+ * The path pattern to match. If unspecified or empty, then this becomes a
736
+ * layout route.
737
+ */
738
+ path?: string;
739
+ /**
740
+ * The unique identifier for this route (for use with {@link DataRouter}s)
741
+ */
742
+ id?: string;
743
+ /**
744
+ * The route middleware.
745
+ * See [`middleware`](../../start/data/route-object#middleware).
746
+ */
747
+ middleware?: MiddlewareFunction[];
748
+ /**
749
+ * The route loader.
750
+ * See [`loader`](../../start/data/route-object#loader).
751
+ */
752
+ loader?: LoaderFunction | boolean;
753
+ /**
754
+ * The route action.
755
+ * See [`action`](../../start/data/route-object#action).
756
+ */
757
+ action?: ActionFunction | boolean;
758
+ hasErrorBoundary?: boolean;
759
+ /**
760
+ * The route shouldRevalidate function.
761
+ * See [`shouldRevalidate`](../../start/data/route-object#shouldRevalidate).
762
+ */
763
+ shouldRevalidate?: ShouldRevalidateFunction;
764
+ /**
765
+ * The route handle.
766
+ */
767
+ handle?: any;
768
+ /**
769
+ * A function that returns a promise that resolves to the route object.
770
+ * Used for code-splitting routes.
771
+ * See [`lazy`](../../start/data/route-object#lazy).
772
+ */
773
+ lazy?: LazyRouteDefinition<BaseRouteObject>;
774
+ /**
775
+ * The React Component to render when this route matches.
776
+ * Mutually exclusive with `element`.
777
+ */
778
+ Component?: React.ComponentType | null;
779
+ /**
780
+ * The React element to render when this Route matches.
781
+ * Mutually exclusive with `Component`.
782
+ */
783
+ element?: React.ReactNode | null;
784
+ /**
785
+ * The React Component to render at this route if an error occurs.
786
+ * Mutually exclusive with `errorElement`.
787
+ */
788
+ ErrorBoundary?: React.ComponentType | null;
789
+ /**
790
+ * The React element to render at this route if an error occurs.
791
+ * Mutually exclusive with `ErrorBoundary`.
792
+ */
793
+ errorElement?: React.ReactNode | null;
794
+ /**
795
+ * The React Component to render while this router is loading data.
796
+ * Mutually exclusive with `hydrateFallbackElement`.
797
+ */
798
+ HydrateFallback?: React.ComponentType | null;
799
+ /**
800
+ * The React element to render while this router is loading data.
801
+ * Mutually exclusive with `HydrateFallback`.
802
+ */
803
+ hydrateFallbackElement?: React.ReactNode | null;
804
+ };
805
+ /**
806
+ * Index routes must not have children
807
+ */
808
+ type IndexRouteObject = BaseRouteObject & {
809
+ /**
810
+ * Child Route objects - not valid on index routes.
811
+ */
812
+ children?: undefined;
813
+ /**
814
+ * Whether this is an index route.
815
+ */
816
+ index: true;
817
+ };
818
+ /**
819
+ * Non-index routes may have children, but cannot have `index` set to `true`.
820
+ */
821
+ type NonIndexRouteObject = BaseRouteObject & {
822
+ /**
823
+ * Child Route objects.
824
+ */
825
+ children?: RouteObject[];
826
+ /**
827
+ * Whether this is an index route - must be `false` or undefined on non-index routes.
828
+ */
829
+ index?: false;
830
+ };
831
+ /**
832
+ * A route object represents a logical route, with (optionally) its child
833
+ * routes organized in a tree-like structure.
834
+ */
835
+ type RouteObject = IndexRouteObject | NonIndexRouteObject;
836
+ type DataIndexRouteObject = IndexRouteObject & {
837
+ id: string;
838
+ };
839
+ type DataNonIndexRouteObject = NonIndexRouteObject & {
840
+ children?: DataRouteObject[];
841
+ id: string;
842
+ };
843
+ /**
844
+ * A data route object, which is just a RouteObject with a required unique ID
845
+ */
846
+ type DataRouteObject = DataIndexRouteObject | DataNonIndexRouteObject;
847
+ type RouteManifest<R = DataRouteObject> = Record<string, R | undefined>;
848
+ 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";
849
+ 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";
850
+ type Regex_09 = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
851
+ type Regex_w = Regex_az | Regez_AZ | Regex_09 | "_";
852
+ type ParamChar = Regex_w | "-";
853
+ 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;
854
+ 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;
855
+ type PathParam<Path extends string> = Path extends "*" | "/*" ? "*" : Path extends `${infer Rest}/*` ? "*" | _PathParam<Rest> : _PathParam<Path>;
856
+ type ParamParseKey<Segment extends string> = [
857
+ PathParam<Segment>
858
+ ] extends [never] ? string : PathParam<Segment>;
859
+ /**
860
+ * The parameters that were parsed from the URL path.
861
+ */
862
+ type Params<Key extends string = string> = {
863
+ readonly [key in Key]: string | undefined;
864
+ };
865
+ /**
866
+ * A RouteMatch contains info about how a route matched a URL.
867
+ */
868
+ interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> {
869
+ /**
870
+ * The names and values of dynamic parameters in the URL.
871
+ */
872
+ params: Params<ParamKey>;
873
+ /**
874
+ * The portion of the URL pathname that was matched.
875
+ */
876
+ pathname: string;
877
+ /**
878
+ * The portion of the URL pathname that was matched before child routes.
879
+ */
880
+ pathnameBase: string;
881
+ /**
882
+ * The route object that was used to match.
883
+ */
884
+ route: RouteObjectType;
885
+ }
886
+ interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
887
+ }
888
+ /**
889
+ * Matches the given routes to a location and returns the match data.
890
+ *
891
+ * @example
892
+ * import { matchRoutes } from "react-router";
893
+ *
894
+ * let routes = [{
895
+ * path: "/",
896
+ * Component: Root,
897
+ * children: [{
898
+ * path: "dashboard",
899
+ * Component: Dashboard,
900
+ * }]
901
+ * }];
902
+ *
903
+ * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
904
+ *
905
+ * @public
906
+ * @category Utils
907
+ * @param routes The array of route objects to match against.
908
+ * @param locationArg The location to match against, either a string path or a
909
+ * partial {@link Location} object
910
+ * @param basename Optional base path to strip from the location before matching.
911
+ * Defaults to `/`.
912
+ * @returns An array of matched routes, or `null` if no matches were found.
913
+ */
914
+ declare function matchRoutes<RouteObjectType extends RouteObject = RouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): RouteMatch<string, RouteObjectType>[] | null;
915
+ interface UIMatch<Data = unknown, Handle = unknown> {
916
+ id: string;
917
+ pathname: string;
918
+ /**
919
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
920
+ */
921
+ params: RouteMatch["params"];
922
+ /**
923
+ * The return value from the matched route's loader or clientLoader. This might
924
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
925
+ * an error and we're currently displaying an `ErrorBoundary`.
926
+ *
927
+ * @deprecated Use `UIMatch.loaderData` instead
928
+ */
929
+ data: Data | undefined;
930
+ /**
931
+ * The return value from the matched route's loader or clientLoader. This might
932
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
933
+ * an error and we're currently displaying an `ErrorBoundary`.
934
+ */
935
+ loaderData: Data | undefined;
936
+ /**
937
+ * The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
938
+ * exported from the matched route module
939
+ */
940
+ handle: Handle;
941
+ }
942
+ /**
943
+ * Returns a path with params interpolated.
944
+ *
945
+ * @example
946
+ * import { generatePath } from "react-router";
947
+ *
948
+ * generatePath("/users/:id", { id: "123" }); // "/users/123"
949
+ *
950
+ * @public
951
+ * @category Utils
952
+ * @param originalPath The original path to generate.
953
+ * @param params The parameters to interpolate into the path.
954
+ * @returns The generated path with parameters interpolated.
955
+ */
956
+ declare function generatePath<Path extends string>(originalPath: Path, params?: {
957
+ [key in PathParam<Path>]: string | null;
958
+ }): string;
959
+ /**
960
+ * Used to match on some portion of a URL pathname.
961
+ */
962
+ interface PathPattern<Path extends string = string> {
963
+ /**
964
+ * A string to match against a URL pathname. May contain `:id`-style segments
965
+ * to indicate placeholders for dynamic parameters. It May also end with `/*`
966
+ * to indicate matching the rest of the URL pathname.
967
+ */
968
+ path: Path;
969
+ /**
970
+ * Should be `true` if the static portions of the `path` should be matched in
971
+ * the same case.
972
+ */
973
+ caseSensitive?: boolean;
974
+ /**
975
+ * Should be `true` if this pattern should match the entire URL pathname.
976
+ */
977
+ end?: boolean;
978
+ }
979
+ /**
980
+ * Contains info about how a {@link PathPattern} matched on a URL pathname.
981
+ */
982
+ interface PathMatch<ParamKey extends string = string> {
983
+ /**
984
+ * The names and values of dynamic parameters in the URL.
985
+ */
986
+ params: Params<ParamKey>;
987
+ /**
988
+ * The portion of the URL pathname that was matched.
989
+ */
990
+ pathname: string;
991
+ /**
992
+ * The portion of the URL pathname that was matched before child routes.
993
+ */
994
+ pathnameBase: string;
995
+ /**
996
+ * The pattern that was used to match.
997
+ */
998
+ pattern: PathPattern;
999
+ }
1000
+ /**
1001
+ * Performs pattern matching on a URL pathname and returns information about
1002
+ * the match.
1003
+ *
1004
+ * @public
1005
+ * @category Utils
1006
+ * @param pattern The pattern to match against the URL pathname. This can be a
1007
+ * string or a {@link PathPattern} object. If a string is provided, it will be
1008
+ * treated as a pattern with `caseSensitive` set to `false` and `end` set to
1009
+ * `true`.
1010
+ * @param pathname The URL pathname to match against the pattern.
1011
+ * @returns A path match object if the pattern matches the pathname,
1012
+ * or `null` if it does not match.
1013
+ */
1014
+ declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
1015
+ /**
1016
+ * Returns a resolved {@link Path} object relative to the given pathname.
1017
+ *
1018
+ * @public
1019
+ * @category Utils
1020
+ * @param to The path to resolve, either a string or a partial {@link Path}
1021
+ * object.
1022
+ * @param fromPathname The pathname to resolve the path from. Defaults to `/`.
1023
+ * @returns A {@link Path} object with the resolved pathname, search, and hash.
1024
+ */
1025
+ declare function resolvePath(to: To, fromPathname?: string): Path;
1026
+ declare class DataWithResponseInit<D> {
1027
+ type: string;
1028
+ data: D;
1029
+ init: ResponseInit | null;
1030
+ constructor(data: D, init?: ResponseInit);
1031
+ }
1032
+ /**
1033
+ * Create "responses" that contain `headers`/`status` without forcing
1034
+ * serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1035
+ *
1036
+ * @example
1037
+ * import { data } from "react-router";
1038
+ *
1039
+ * export async function action({ request }: Route.ActionArgs) {
1040
+ * let formData = await request.formData();
1041
+ * let item = await createItem(formData);
1042
+ * return data(item, {
1043
+ * headers: { "X-Custom-Header": "value" }
1044
+ * status: 201,
1045
+ * });
1046
+ * }
1047
+ *
1048
+ * @public
1049
+ * @category Utils
1050
+ * @mode framework
1051
+ * @mode data
1052
+ * @param data The data to be included in the response.
1053
+ * @param init The status code or a `ResponseInit` object to be included in the
1054
+ * response.
1055
+ * @returns A {@link DataWithResponseInit} instance containing the data and
1056
+ * response init.
1057
+ */
1058
+ declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
1059
+ interface TrackedPromise extends Promise<any> {
1060
+ _tracked?: boolean;
1061
+ _data?: any;
1062
+ _error?: any;
1063
+ }
1064
+ type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
1065
+ /**
1066
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
1067
+ * Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
1068
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
1069
+ *
1070
+ * @example
1071
+ * import { redirect } from "react-router";
1072
+ *
1073
+ * export async function loader({ request }: Route.LoaderArgs) {
1074
+ * if (!isLoggedIn(request))
1075
+ * throw redirect("/login");
1076
+ * }
1077
+ *
1078
+ * // ...
1079
+ * }
1080
+ *
1081
+ * @public
1082
+ * @category Utils
1083
+ * @mode framework
1084
+ * @mode data
1085
+ * @param url The URL to redirect to.
1086
+ * @param init The status code or a `ResponseInit` object to be included in the
1087
+ * response.
1088
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1089
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
1090
+ * header.
1091
+ */
1092
+ declare const redirect: RedirectFunction;
1093
+ /**
1094
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1095
+ * that will force a document reload to the new location. Sets the status code
1096
+ * and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
1097
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
1098
+ *
1099
+ * ```tsx filename=routes/logout.tsx
1100
+ * import { redirectDocument } from "react-router";
1101
+ *
1102
+ * import { destroySession } from "../sessions.server";
1103
+ *
1104
+ * export async function action({ request }: Route.ActionArgs) {
1105
+ * let session = await getSession(request.headers.get("Cookie"));
1106
+ * return redirectDocument("/", {
1107
+ * headers: { "Set-Cookie": await destroySession(session) }
1108
+ * });
1109
+ * }
1110
+ * ```
1111
+ *
1112
+ * @public
1113
+ * @category Utils
1114
+ * @mode framework
1115
+ * @mode data
1116
+ * @param url The URL to redirect to.
1117
+ * @param init The status code or a `ResponseInit` object to be included in the
1118
+ * response.
1119
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1120
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
1121
+ * header.
1122
+ */
1123
+ declare const redirectDocument: RedirectFunction;
1124
+ /**
1125
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1126
+ * that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
1127
+ * instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
1128
+ * for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
1129
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
1130
+ *
1131
+ * @example
1132
+ * import { replace } from "react-router";
1133
+ *
1134
+ * export async function loader() {
1135
+ * return replace("/new-location");
1136
+ * }
1137
+ *
1138
+ * @public
1139
+ * @category Utils
1140
+ * @mode framework
1141
+ * @mode data
1142
+ * @param url The URL to redirect to.
1143
+ * @param init The status code or a `ResponseInit` object to be included in the
1144
+ * response.
1145
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1146
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
1147
+ * header.
1148
+ */
1149
+ declare const replace: RedirectFunction;
1150
+ type ErrorResponse = {
1151
+ status: number;
1152
+ statusText: string;
1153
+ data: any;
1154
+ };
1155
+ declare class ErrorResponseImpl implements ErrorResponse {
1156
+ status: number;
1157
+ statusText: string;
1158
+ data: any;
1159
+ private error?;
1160
+ private internal;
1161
+ constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
1162
+ }
1163
+ /**
1164
+ * Check if the given error is an {@link ErrorResponse} generated from a 4xx/5xx
1165
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1166
+ * thrown from an [`action`](../../start/framework/route-module#action) or
1167
+ * [`loader`](../../start/framework/route-module#loader) function.
1168
+ *
1169
+ * @example
1170
+ * import { isRouteErrorResponse } from "react-router";
1171
+ *
1172
+ * export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
1173
+ * if (isRouteErrorResponse(error)) {
1174
+ * return (
1175
+ * <>
1176
+ * <p>Error: `${error.status}: ${error.statusText}`</p>
1177
+ * <p>{error.data}</p>
1178
+ * </>
1179
+ * );
1180
+ * }
1181
+ *
1182
+ * return (
1183
+ * <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
1184
+ * );
1185
+ * }
1186
+ *
1187
+ * @public
1188
+ * @category Utils
1189
+ * @mode framework
1190
+ * @mode data
1191
+ * @param error The error to check.
1192
+ * @returns `true` if the error is an {@link ErrorResponse}, `false` otherwise.
1193
+ */
1194
+ declare function isRouteErrorResponse(error: any): error is ErrorResponse;
1195
+
1196
+ /**
1197
+ * An object of unknown type for route loaders and actions provided by the
1198
+ * server's `getLoadContext()` function. This is defined as an empty interface
1199
+ * specifically so apps can leverage declaration merging to augment this type
1200
+ * globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
1201
+ */
1202
+ interface AppLoadContext {
1203
+ [key: string]: unknown;
1204
+ }
1205
+
1206
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1207
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1208
+ interface HtmlLinkProps {
1209
+ /**
1210
+ * Address of the hyperlink
1211
+ */
1212
+ href?: string;
1213
+ /**
1214
+ * How the element handles crossorigin requests
1215
+ */
1216
+ crossOrigin?: "anonymous" | "use-credentials";
1217
+ /**
1218
+ * Relationship between the document containing the hyperlink and the destination resource
1219
+ */
1220
+ rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
1221
+ /**
1222
+ * Applicable media: "screen", "print", "(max-width: 764px)"
1223
+ */
1224
+ media?: string;
1225
+ /**
1226
+ * Integrity metadata used in Subresource Integrity checks
1227
+ */
1228
+ integrity?: string;
1229
+ /**
1230
+ * Language of the linked resource
1231
+ */
1232
+ hrefLang?: string;
1233
+ /**
1234
+ * Hint for the type of the referenced resource
1235
+ */
1236
+ type?: string;
1237
+ /**
1238
+ * Referrer policy for fetches initiated by the element
1239
+ */
1240
+ referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
1241
+ /**
1242
+ * Sizes of the icons (for rel="icon")
1243
+ */
1244
+ sizes?: string;
1245
+ /**
1246
+ * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1247
+ */
1248
+ as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
1249
+ /**
1250
+ * Color to use when customizing a site's icon (for rel="mask-icon")
1251
+ */
1252
+ color?: string;
1253
+ /**
1254
+ * Whether the link is disabled
1255
+ */
1256
+ disabled?: boolean;
1257
+ /**
1258
+ * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
1259
+ */
1260
+ title?: string;
1261
+ /**
1262
+ * Images to use in different situations, e.g., high-resolution displays,
1263
+ * small monitors, etc. (for rel="preload")
1264
+ */
1265
+ imageSrcSet?: string;
1266
+ /**
1267
+ * Image sizes for different page layouts (for rel="preload")
1268
+ */
1269
+ imageSizes?: string;
1270
+ }
1271
+ interface HtmlLinkPreloadImage extends HtmlLinkProps {
1272
+ /**
1273
+ * Relationship between the document containing the hyperlink and the destination resource
1274
+ */
1275
+ rel: "preload";
1276
+ /**
1277
+ * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1278
+ */
1279
+ as: "image";
1280
+ /**
1281
+ * Address of the hyperlink
1282
+ */
1283
+ href?: string;
1284
+ /**
1285
+ * Images to use in different situations, e.g., high-resolution displays,
1286
+ * small monitors, etc. (for rel="preload")
1287
+ */
1288
+ imageSrcSet: string;
1289
+ /**
1290
+ * Image sizes for different page layouts (for rel="preload")
1291
+ */
1292
+ imageSizes?: string;
1293
+ }
1294
+ /**
1295
+ * Represents a `<link>` element.
1296
+ *
1297
+ * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
1298
+ */
1299
+ type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
1300
+ imageSizes?: never;
1301
+ });
1302
+ interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1303
+ /**
1304
+ * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
1305
+ * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
1306
+ * element
1307
+ */
1308
+ nonce?: string | undefined;
1309
+ /**
1310
+ * The absolute path of the page to prefetch, e.g. `/absolute/path`.
1311
+ */
1312
+ page: string;
1313
+ }
1314
+ type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1315
+
1316
+ type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1317
+ [key: PropertyKey]: Serializable;
1318
+ } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
1319
+
1320
+ type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
1321
+ type IsAny<T> = 0 extends 1 & T ? true : false;
1322
+ type Func = (...args: any[]) => unknown;
1323
+ type Pretty<T> = {
1324
+ [K in keyof T]: T[K];
1325
+ } & {};
1326
+ type Normalize<T> = _Normalize<UnionKeys<T>, T>;
1327
+ type _Normalize<Key extends keyof any, T> = T extends infer U ? Pretty<{
1328
+ [K in Key as K extends keyof U ? undefined extends U[K] ? never : K : never]: K extends keyof U ? U[K] : never;
1329
+ } & {
1330
+ [K in Key as K extends keyof U ? undefined extends U[K] ? K : never : never]?: K extends keyof U ? U[K] : never;
1331
+ } & {
1332
+ [K in Key as K extends keyof U ? never : K]?: undefined;
1333
+ }> : never;
1334
+ type UnionKeys<T> = T extends any ? keyof T : never;
1335
+
1336
+ type RouteModule$1 = {
1337
+ meta?: Func;
1338
+ links?: Func;
1339
+ headers?: Func;
1340
+ loader?: Func;
1341
+ clientLoader?: Func;
1342
+ action?: Func;
1343
+ clientAction?: Func;
1344
+ HydrateFallback?: Func;
1345
+ default?: Func;
1346
+ ErrorBoundary?: Func;
1347
+ [key: string]: unknown;
1348
+ };
1349
+
1350
+ /**
1351
+ * A brand that can be applied to a type to indicate that it will serialize
1352
+ * to a specific type when transported to the client from a loader.
1353
+ * Only use this if you have additional serialization/deserialization logic
1354
+ * in your application.
1355
+ */
1356
+ type unstable_SerializesTo<T> = {
1357
+ unstable__ReactRouter_SerializesTo: [T];
1358
+ };
1359
+
1360
+ type Serialize<T> = T extends unstable_SerializesTo<infer To> ? To : T extends Serializable ? T : T extends (...args: any[]) => unknown ? undefined : T extends Promise<infer U> ? Promise<Serialize<U>> : T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<Serialize<K>, Serialize<V>> : T extends Set<infer U> ? Set<Serialize<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<Serialize<U>> : T extends [] ? [] : T extends readonly [infer F, ...infer R] ? [Serialize<F>, ...Serialize<R>] : T extends Array<infer U> ? Array<Serialize<U>> : T extends readonly unknown[] ? readonly Serialize<T[number]>[] : T extends Record<any, any> ? {
1361
+ [K in keyof T]: Serialize<T[K]>;
1362
+ } : undefined;
1363
+ type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1364
+ type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1365
+ type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1366
+ type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1367
+ type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1368
+ type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1369
+ type ClientDataFunctionArgs<Params> = {
1370
+ /**
1371
+ * A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the URL, the method, the "content-type" header, and the request body from the request.
1372
+ *
1373
+ * @note Because client data functions are called before a network request is made, the Request object does not include the headers which the browser automatically adds. React Router infers the "content-type" header from the enc-type of the form that performed the submission.
1374
+ **/
1375
+ request: Request;
1376
+ /**
1377
+ * A URL instance representing the application location being navigated to or fetched.
1378
+ * Without `future.unstable_passThroughRequests` enabled, this matches `request.url`.
1379
+ * With `future.unstable_passThroughRequests` enabled, this is a normalized
1380
+ * URL with React-Router-specific implementation details removed (`.data`
1381
+ * pathnames, `index`/`_routes` search params).
1382
+ * The URL includes the origin from the request for convenience.
1383
+ */
1384
+ unstable_url: URL;
1385
+ /**
1386
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
1387
+ * @example
1388
+ * // app/routes.ts
1389
+ * route("teams/:teamId", "./team.tsx"),
1390
+ *
1391
+ * // app/team.tsx
1392
+ * export function clientLoader({
1393
+ * params,
1394
+ * }: Route.ClientLoaderArgs) {
1395
+ * params.teamId;
1396
+ * // ^ string
1397
+ * }
1398
+ **/
1399
+ params: Params;
1400
+ /**
1401
+ * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
1402
+ * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
1403
+ */
1404
+ unstable_pattern: string;
1405
+ /**
1406
+ * When `future.v8_middleware` is not enabled, this is undefined.
1407
+ *
1408
+ * When `future.v8_middleware` is enabled, this is an instance of
1409
+ * `RouterContextProvider` and can be used to access context values
1410
+ * from your route middlewares. You may pass in initial context values in your
1411
+ * `<HydratedRouter getContext>` prop
1412
+ */
1413
+ context: Readonly<RouterContextProvider>;
1414
+ };
1415
+ type ServerDataFunctionArgs<Params> = {
1416
+ /** A {@link https://developer.mozilla.org/en-US/docs/Web/API/Request Fetch Request instance} which you can use to read the url, method, headers (such as cookies), and request body from the request. */
1417
+ request: Request;
1418
+ /**
1419
+ * A URL instance representing the application location being navigated to or fetched.
1420
+ * Without `future.unstable_passThroughRequests` enabled, this matches `request.url`.
1421
+ * With `future.unstable_passThroughRequests` enabled, this is a normalized
1422
+ * URL with React-Router-specific implementation details removed (`.data`
1423
+ * pathnames, `index`/`_routes` search params).
1424
+ * The URL includes the origin from the request for convenience.
1425
+ */
1426
+ unstable_url: URL;
1427
+ /**
1428
+ * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
1429
+ * @example
1430
+ * // app/routes.ts
1431
+ * route("teams/:teamId", "./team.tsx"),
1432
+ *
1433
+ * // app/team.tsx
1434
+ * export function loader({
1435
+ * params,
1436
+ * }: Route.LoaderArgs) {
1437
+ * params.teamId;
1438
+ * // ^ string
1439
+ * }
1440
+ **/
1441
+ params: Params;
1442
+ /**
1443
+ * Matched un-interpolated route pattern for the current path (i.e., /blog/:slug).
1444
+ * Mostly useful as a identifier to aggregate on for logging/tracing/etc.
1445
+ */
1446
+ unstable_pattern: string;
1447
+ /**
1448
+ * Without `future.v8_middleware` enabled, this is the context passed in
1449
+ * to your server adapter's `getLoadContext` function. It's a way to bridge the
1450
+ * gap between the adapter's request/response API with your React Router app.
1451
+ * It is only applicable if you are using a custom server adapter.
1452
+ *
1453
+ * With `future.v8_middleware` enabled, this is an instance of
1454
+ * `RouterContextProvider` and can be used for type-safe access to
1455
+ * context value set in your route middlewares. If you are using a custom
1456
+ * server adapter, you may provide an initial set of context values from your
1457
+ * `getLoadContext` function.
1458
+ */
1459
+ context: MiddlewareEnabled extends true ? Readonly<RouterContextProvider> : AppLoadContext;
1460
+ };
1461
+ type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
1462
+ ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
1463
+ ] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1464
+ type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
1465
+ type IsHydrate<ClientLoader> = ClientLoader extends {
1466
+ hydrate: true;
1467
+ } ? true : ClientLoader extends {
1468
+ hydrate: false;
1469
+ } ? false : false;
1470
+ type GetLoaderData<T extends RouteModule$1> = _DataLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
1471
+ HydrateFallback: Func;
1472
+ } ? true : false>;
1473
+ type _DataLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [
1474
+ HasHydrateFallback,
1475
+ ClientLoaderHydrate
1476
+ ] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [
1477
+ IsDefined<ClientLoaderData>,
1478
+ IsDefined<ServerLoaderData>
1479
+ ] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderData : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
1480
+ type GetActionData<T extends RouteModule$1> = _DataActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
1481
+ type _DataActionData<ServerActionData, ClientActionData> = Awaited<[
1482
+ IsDefined<ServerActionData>,
1483
+ IsDefined<ClientActionData>
1484
+ ] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
1485
+
1486
+ interface RouteModules {
1487
+ [routeId: string]: RouteModule | undefined;
1488
+ }
1489
+ /**
1490
+ * The shape of a route module shipped to the client
1491
+ */
1492
+ interface RouteModule {
1493
+ clientAction?: ClientActionFunction;
1494
+ clientLoader?: ClientLoaderFunction;
1495
+ clientMiddleware?: MiddlewareFunction<Record<string, DataStrategyResult>>[];
1496
+ ErrorBoundary?: ErrorBoundaryComponent;
1497
+ HydrateFallback?: HydrateFallbackComponent;
1498
+ Layout?: LayoutComponent;
1499
+ default: RouteComponent;
1500
+ handle?: RouteHandle;
1501
+ links?: LinksFunction;
1502
+ meta?: MetaFunction;
1503
+ shouldRevalidate?: ShouldRevalidateFunction;
1504
+ }
1505
+ /**
1506
+ * The shape of a route module on the server
1507
+ */
1508
+ interface ServerRouteModule extends RouteModule {
1509
+ action?: ActionFunction;
1510
+ headers?: HeadersFunction | {
1511
+ [name: string]: string;
1512
+ };
1513
+ loader?: LoaderFunction;
1514
+ middleware?: MiddlewareFunction<Response>[];
1515
+ }
1516
+ /**
1517
+ * A function that handles data mutations for a route on the client
1518
+ */
1519
+ type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
1520
+ /**
1521
+ * Arguments passed to a route `clientAction` function
1522
+ */
1523
+ type ClientActionFunctionArgs = ActionFunctionArgs & {
1524
+ serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1525
+ };
1526
+ /**
1527
+ * A function that loads data for a route on the client
1528
+ */
1529
+ type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
1530
+ hydrate?: boolean;
1531
+ };
1532
+ /**
1533
+ * Arguments passed to a route `clientLoader` function
1534
+ */
1535
+ type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1536
+ serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1537
+ };
1538
+ /**
1539
+ * ErrorBoundary to display for this route
1540
+ */
1541
+ type ErrorBoundaryComponent = ComponentType;
1542
+ type HeadersArgs = {
1543
+ loaderHeaders: Headers;
1544
+ parentHeaders: Headers;
1545
+ actionHeaders: Headers;
1546
+ errorHeaders: Headers | undefined;
1547
+ };
1548
+ /**
1549
+ * A function that returns HTTP headers to be used for a route. These headers
1550
+ * will be merged with (and take precedence over) headers from parent routes.
1551
+ */
1552
+ interface HeadersFunction {
1553
+ (args: HeadersArgs): Headers | HeadersInit;
1554
+ }
1555
+ /**
1556
+ * `<Route HydrateFallback>` component to render on initial loads
1557
+ * when client loaders are present
1558
+ */
1559
+ type HydrateFallbackComponent = ComponentType;
1560
+ /**
1561
+ * Optional, root-only `<Route Layout>` component to wrap the root content in.
1562
+ * Useful for defining the <html>/<head>/<body> document shell shared by the
1563
+ * Component, HydrateFallback, and ErrorBoundary
1564
+ */
1565
+ type LayoutComponent = ComponentType<{
1566
+ children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
1567
+ }>;
1568
+ /**
1569
+ * A function that defines `<link>` tags to be inserted into the `<head>` of
1570
+ * the document on route transitions.
1571
+ *
1572
+ * @see https://reactrouter.com/start/framework/route-module#meta
1573
+ */
1574
+ interface LinksFunction {
1575
+ (): LinkDescriptor[];
1576
+ }
1577
+ interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1578
+ id: RouteId;
1579
+ pathname: DataRouteMatch["pathname"];
1580
+ /** @deprecated Use `MetaMatch.loaderData` instead */
1581
+ data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1582
+ loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1583
+ handle?: RouteHandle;
1584
+ params: DataRouteMatch["params"];
1585
+ meta: MetaDescriptor[];
1586
+ error?: unknown;
1587
+ }
1588
+ type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
1589
+ [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1590
+ }[keyof MatchLoaders]>;
1591
+ interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1592
+ /** @deprecated Use `MetaArgs.loaderData` instead */
1593
+ data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1594
+ loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1595
+ params: Params;
1596
+ location: Location;
1597
+ matches: MetaMatches<MatchLoaders>;
1598
+ error?: unknown;
1599
+ }
1600
+ /**
1601
+ * A function that returns an array of data objects to use for rendering
1602
+ * metadata HTML tags in a route. These tags are not rendered on descendant
1603
+ * routes in the route hierarchy. In other words, they will only be rendered on
1604
+ * the route in which they are exported.
1605
+ *
1606
+ * @param Loader - The type of the current route's loader function
1607
+ * @param MatchLoaders - Mapping from a parent route's filepath to its loader
1608
+ * function type
1609
+ *
1610
+ * Note that parent route filepaths are relative to the `app/` directory.
1611
+ *
1612
+ * For example, if this meta function is for `/sales/customers/$customerId`:
1613
+ *
1614
+ * ```ts
1615
+ * // app/root.tsx
1616
+ * const loader = () => ({ hello: "world" })
1617
+ * export type Loader = typeof loader
1618
+ *
1619
+ * // app/routes/sales.tsx
1620
+ * const loader = () => ({ salesCount: 1074 })
1621
+ * export type Loader = typeof loader
1622
+ *
1623
+ * // app/routes/sales/customers.tsx
1624
+ * const loader = () => ({ customerCount: 74 })
1625
+ * export type Loader = typeof loader
1626
+ *
1627
+ * // app/routes/sales/customers/$customersId.tsx
1628
+ * import type { Loader as RootLoader } from "../../../root"
1629
+ * import type { Loader as SalesLoader } from "../../sales"
1630
+ * import type { Loader as CustomersLoader } from "../../sales/customers"
1631
+ *
1632
+ * const loader = () => ({ name: "Customer name" })
1633
+ *
1634
+ * const meta: MetaFunction<typeof loader, {
1635
+ * "root": RootLoader,
1636
+ * "routes/sales": SalesLoader,
1637
+ * "routes/sales/customers": CustomersLoader,
1638
+ * }> = ({ data, matches }) => {
1639
+ * const { name } = data
1640
+ * // ^? string
1641
+ * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
1642
+ * // ^? number
1643
+ * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
1644
+ * // ^? number
1645
+ * const { hello } = matches.find((match) => match.id === "root").data
1646
+ * // ^? "world"
1647
+ * }
1648
+ * ```
1649
+ */
1650
+ interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1651
+ (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
1652
+ }
1653
+ type MetaDescriptor = {
1654
+ charSet: "utf-8";
1655
+ } | {
1656
+ title: string;
1657
+ } | {
1658
+ name: string;
1659
+ content: string;
1660
+ } | {
1661
+ property: string;
1662
+ content: string;
1663
+ } | {
1664
+ httpEquiv: string;
1665
+ content: string;
1666
+ } | {
1667
+ "script:ld+json": LdJsonObject;
1668
+ } | {
1669
+ tagName: "meta" | "link";
1670
+ [name: string]: string;
1671
+ } | {
1672
+ [name: string]: unknown;
1673
+ };
1674
+ type LdJsonObject = {
1675
+ [Key in string]: LdJsonValue;
1676
+ } & {
1677
+ [Key in string]?: LdJsonValue | undefined;
1678
+ };
1679
+ type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
1680
+ type LdJsonPrimitive = string | number | boolean | null;
1681
+ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
1682
+ /**
1683
+ * A React component that is rendered for a route.
1684
+ */
1685
+ type RouteComponent = ComponentType<{}>;
1686
+ /**
1687
+ * An arbitrary object that is associated with a route.
1688
+ *
1689
+ * @see https://reactrouter.com/how-to/using-handle
1690
+ */
1691
+ type RouteHandle = unknown;
1692
+
1693
+ export { type PathMatch as $, type ActionFunction as A, type PatchRoutesOnNavigationFunction as B, type ClientActionFunction as C, type DataStrategyResult as D, type DataRouteObject as E, type Func as F, type GetLoaderData as G, type HeadersFunction as H, type Path as I, type InitialEntry as J, type NonIndexRouteObject as K, type Location as L, type MetaFunction as M, type Normalize as N, type LazyRouteFunction as O, type Params as P, type IndexRouteObject as Q, type RouteModule$1 as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type RouteMatch as V, type TrackedPromise as W, type RouteModules as X, type SerializeFrom as Y, type ParamParseKey as Z, type PathPattern as _, type ClientLoaderFunction as a, type Equal as a0, type ActionFunctionArgs as a1, type BaseRouteObject as a2, type DataStrategyFunctionArgs as a3, type DataStrategyMatch as a4, DataWithResponseInit as a5, type ErrorResponse as a6, type FormMethod as a7, type MiddlewareFunction as a8, type PatchRoutesOnNavigationFunctionArgs as a9, createHashHistory as aA, invariant as aB, ErrorResponseImpl as aC, type RouteManifest as aD, type ServerRouteModule as aE, type PathParam as aa, type RedirectFunction as ab, type RouterContext as ac, type ShouldRevalidateFunctionArgs as ad, createContext as ae, createPath as af, parsePath as ag, data as ah, generatePath as ai, isRouteErrorResponse as aj, matchPath as ak, matchRoutes as al, redirect as am, redirectDocument as an, replace as ao, resolvePath 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 Future as aw, type unstable_SerializesTo as ax, createMemoryHistory as ay, createBrowserHistory as az, type LinksFunction as b, RouterContextProvider as c, type LoaderFunction as d, type LinkDescriptor as e, type Pretty as f, type MetaDescriptor as g, type ServerDataFunctionArgs as h, type MiddlewareNextFunction as i, type ClientDataFunctionArgs as j, type ServerDataFrom as k, type GetActionData as l, type HTMLFormMethod as m, type FormEncType as n, type LoaderFunctionArgs as o, type MiddlewareEnabled as p, type AppLoadContext as q, type RouteObject as r, type History as s, type MaybePromise as t, type MapRoutePropertiesFunction as u, Action as v, type DataRouteMatch as w, type Submission as x, type RouteData as y, type DataStrategyFunction as z };