react-router 0.0.0-experimental-a6d1d1d4e → 0.0.0-experimental-1d760f6a6

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 (44) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/development/{chunk-OEAMHMGQ.mjs → chunk-QBMD7MNB.mjs} +293 -1025
  3. package/dist/development/dom-export.d.mts +2 -2
  4. package/dist/development/dom-export.d.ts +2 -2
  5. package/dist/development/dom-export.js +69 -103
  6. package/dist/development/dom-export.mjs +2 -2
  7. package/dist/development/{fog-of-war-DrUCUQQ-.d.ts → fog-of-war-BLArG-qZ.d.ts} +81 -168
  8. package/dist/{production/fog-of-war-C5L_Yd5M.d.mts → development/fog-of-war-D2zsXvum.d.mts} +81 -168
  9. package/dist/development/index.d.mts +8 -15
  10. package/dist/development/index.d.ts +8 -15
  11. package/dist/development/index.js +291 -1032
  12. package/dist/development/index.mjs +2 -19
  13. package/dist/development/lib/types/route-module.d.mts +1 -1
  14. package/dist/development/lib/types/route-module.d.ts +1 -1
  15. package/dist/development/lib/types/route-module.js +1 -1
  16. package/dist/development/lib/types/route-module.mjs +1 -1
  17. package/dist/development/{route-data-BIYebJr3.d.ts → route-data-C12CLHiN.d.mts} +1 -11
  18. package/dist/{production/route-data-BIYebJr3.d.mts → development/route-data-C12CLHiN.d.ts} +1 -11
  19. package/dist/production/{chunk-I2N4LFMP.mjs → chunk-DSJGM2GU.mjs} +293 -1025
  20. package/dist/production/dom-export.d.mts +2 -2
  21. package/dist/production/dom-export.d.ts +2 -2
  22. package/dist/production/dom-export.js +69 -103
  23. package/dist/production/dom-export.mjs +2 -2
  24. package/dist/production/{fog-of-war-DrUCUQQ-.d.ts → fog-of-war-BLArG-qZ.d.ts} +81 -168
  25. package/dist/{development/fog-of-war-C5L_Yd5M.d.mts → production/fog-of-war-D2zsXvum.d.mts} +81 -168
  26. package/dist/production/index.d.mts +8 -15
  27. package/dist/production/index.d.ts +8 -15
  28. package/dist/production/index.js +291 -1032
  29. package/dist/production/index.mjs +2 -19
  30. package/dist/production/lib/types/route-module.d.mts +1 -1
  31. package/dist/production/lib/types/route-module.d.ts +1 -1
  32. package/dist/production/lib/types/route-module.js +1 -1
  33. package/dist/production/lib/types/route-module.mjs +1 -1
  34. package/dist/production/{route-data-BIYebJr3.d.ts → route-data-C12CLHiN.d.mts} +1 -11
  35. package/dist/{development/route-data-BIYebJr3.d.mts → production/route-data-C12CLHiN.d.ts} +1 -11
  36. package/package.json +2 -33
  37. package/dist/development/rsc-export.d.mts +0 -1553
  38. package/dist/development/rsc-export.d.ts +0 -1553
  39. package/dist/development/rsc-export.js +0 -2413
  40. package/dist/development/rsc-export.mjs +0 -2385
  41. package/dist/production/rsc-export.d.mts +0 -1553
  42. package/dist/production/rsc-export.d.ts +0 -1553
  43. package/dist/production/rsc-export.js +0 -2413
  44. package/dist/production/rsc-export.mjs +0 -2385
@@ -1,1553 +0,0 @@
1
- import * as React from 'react';
2
-
3
- /**
4
- * Actions represent the type of change to a location value.
5
- */
6
- declare enum Action {
7
- /**
8
- * A POP indicates a change to an arbitrary index in the history stack, such
9
- * as a back or forward navigation. It does not describe the direction of the
10
- * navigation, only that the current index changed.
11
- *
12
- * Note: This is the default action for newly created history objects.
13
- */
14
- Pop = "POP",
15
- /**
16
- * A PUSH indicates a new entry being added to the history stack, such as when
17
- * a link is clicked and a new page loads. When this happens, all subsequent
18
- * entries in the stack are lost.
19
- */
20
- Push = "PUSH",
21
- /**
22
- * A REPLACE indicates the entry at the current index in the history stack
23
- * being replaced by a new one.
24
- */
25
- Replace = "REPLACE"
26
- }
27
- /**
28
- * The pathname, search, and hash values of a URL.
29
- */
30
- interface Path {
31
- /**
32
- * A URL pathname, beginning with a /.
33
- */
34
- pathname: string;
35
- /**
36
- * A URL search string, beginning with a ?.
37
- */
38
- search: string;
39
- /**
40
- * A URL fragment identifier, beginning with a #.
41
- */
42
- hash: string;
43
- }
44
- /**
45
- * An entry in a history stack. A location contains information about the
46
- * URL path, as well as possibly some arbitrary state and a key.
47
- */
48
- interface Location<State = any> extends Path {
49
- /**
50
- * A value of arbitrary data associated with this location.
51
- */
52
- state: State;
53
- /**
54
- * A unique string associated with this location. May be used to safely store
55
- * and retrieve data in some other storage API, like `localStorage`.
56
- *
57
- * Note: This value is always "default" on the initial location.
58
- */
59
- key: string;
60
- }
61
- /**
62
- * A change to the current location.
63
- */
64
- interface Update {
65
- /**
66
- * The action that triggered the change.
67
- */
68
- action: Action;
69
- /**
70
- * The new location.
71
- */
72
- location: Location;
73
- /**
74
- * The delta between this location and the former location in the history stack
75
- */
76
- delta: number | null;
77
- }
78
- /**
79
- * A function that receives notifications about location changes.
80
- */
81
- interface Listener {
82
- (update: Update): void;
83
- }
84
- /**
85
- * Describes a location that is the destination of some navigation used in
86
- * {@link Link}, {@link useNavigate}, etc.
87
- */
88
- type To = string | Partial<Path>;
89
- /**
90
- * A history is an interface to the navigation stack. The history serves as the
91
- * source of truth for the current location, as well as provides a set of
92
- * methods that may be used to change it.
93
- *
94
- * It is similar to the DOM's `window.history` object, but with a smaller, more
95
- * focused API.
96
- */
97
- interface History {
98
- /**
99
- * The last action that modified the current location. This will always be
100
- * Action.Pop when a history instance is first created. This value is mutable.
101
- */
102
- readonly action: Action;
103
- /**
104
- * The current location. This value is mutable.
105
- */
106
- readonly location: Location;
107
- /**
108
- * Returns a valid href for the given `to` value that may be used as
109
- * the value of an <a href> attribute.
110
- *
111
- * @param to - The destination URL
112
- */
113
- createHref(to: To): string;
114
- /**
115
- * Returns a URL for the given `to` value
116
- *
117
- * @param to - The destination URL
118
- */
119
- createURL(to: To): URL;
120
- /**
121
- * Encode a location the same way window.history would do (no-op for memory
122
- * history) so we ensure our PUSH/REPLACE navigations for data routers
123
- * behave the same as POP
124
- *
125
- * @param to Unencoded path
126
- */
127
- encodeLocation(to: To): Path;
128
- /**
129
- * Pushes a new location onto the history stack, increasing its length by one.
130
- * If there were any entries in the stack after the current one, they are
131
- * lost.
132
- *
133
- * @param to - The new URL
134
- * @param state - Data to associate with the new location
135
- */
136
- push(to: To, state?: any): void;
137
- /**
138
- * Replaces the current location in the history stack with a new one. The
139
- * location that was replaced will no longer be available.
140
- *
141
- * @param to - The new URL
142
- * @param state - Data to associate with the new location
143
- */
144
- replace(to: To, state?: any): void;
145
- /**
146
- * Navigates `n` entries backward/forward in the history stack relative to the
147
- * current index. For example, a "back" navigation would use go(-1).
148
- *
149
- * @param delta - The delta in the stack index
150
- */
151
- go(delta: number): void;
152
- /**
153
- * Sets up a listener that will be called whenever the current location
154
- * changes.
155
- *
156
- * @param listener - A function that will be called when the location changes
157
- * @returns unlisten - A function that may be used to stop listening
158
- */
159
- listen(listener: Listener): () => void;
160
- }
161
-
162
- /**
163
- * An augmentable interface users can modify in their app-code to opt into
164
- * future-flag-specific types
165
- */
166
- interface Future {
167
- }
168
- type MiddlewareEnabled = Future extends {
169
- unstable_middleware: infer T extends boolean;
170
- } ? T : false;
171
-
172
- type MaybePromise<T> = T | Promise<T>;
173
- /**
174
- * Map of routeId -> data returned from a loader/action/error
175
- */
176
- interface RouteData {
177
- [routeId: string]: any;
178
- }
179
- type LowerCaseFormMethod = "get" | "post" | "put" | "patch" | "delete";
180
- type UpperCaseFormMethod = Uppercase<LowerCaseFormMethod>;
181
- /**
182
- * Users can specify either lowercase or uppercase form methods on `<Form>`,
183
- * useSubmit(), `<fetcher.Form>`, etc.
184
- */
185
- type HTMLFormMethod = LowerCaseFormMethod | UpperCaseFormMethod;
186
- /**
187
- * Active navigation/fetcher form methods are exposed in uppercase on the
188
- * RouterState. This is to align with the normalization done via fetch().
189
- */
190
- type FormMethod = UpperCaseFormMethod;
191
- type FormEncType = "application/x-www-form-urlencoded" | "multipart/form-data" | "application/json" | "text/plain";
192
- type JsonObject = {
193
- [Key in string]: JsonValue;
194
- } & {
195
- [Key in string]?: JsonValue | undefined;
196
- };
197
- type JsonArray = JsonValue[] | readonly JsonValue[];
198
- type JsonPrimitive = string | number | boolean | null;
199
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
200
- /**
201
- * @private
202
- * Internal interface to pass around for action submissions, not intended for
203
- * external consumption
204
- */
205
- type Submission = {
206
- formMethod: FormMethod;
207
- formAction: string;
208
- formEncType: FormEncType;
209
- formData: FormData;
210
- json: undefined;
211
- text: undefined;
212
- } | {
213
- formMethod: FormMethod;
214
- formAction: string;
215
- formEncType: FormEncType;
216
- formData: undefined;
217
- json: JsonValue;
218
- text: undefined;
219
- } | {
220
- formMethod: FormMethod;
221
- formAction: string;
222
- formEncType: FormEncType;
223
- formData: undefined;
224
- json: undefined;
225
- text: string;
226
- };
227
- interface unstable_RouterContext<T = unknown> {
228
- defaultValue?: T;
229
- }
230
- /**
231
- * A Map of RouterContext objects to their initial values - used to populate a
232
- * fresh `context` value per request/navigation/fetch
233
- */
234
- type unstable_InitialContext = Map<unstable_RouterContext, unknown>;
235
- /**
236
- * Provides methods for writing/reading values in application context in a typesafe way.
237
- */
238
- declare class unstable_RouterContextProvider {
239
- #private;
240
- constructor(init?: unstable_InitialContext);
241
- get<T>(context: unstable_RouterContext<T>): T;
242
- set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
243
- }
244
- type DefaultContext = MiddlewareEnabled extends true ? unstable_RouterContextProvider : any;
245
- /**
246
- * @private
247
- * Arguments passed to route loader/action functions. Same for now but we keep
248
- * this as a private implementation detail in case they diverge in the future.
249
- */
250
- interface DataFunctionArgs<Context> {
251
- /** 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. */
252
- request: Request;
253
- /**
254
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
255
- * @example
256
- * // app/routes.ts
257
- * route("teams/:teamId", "./team.tsx"),
258
- *
259
- * // app/team.tsx
260
- * export function loader({
261
- * params,
262
- * }: Route.LoaderArgs) {
263
- * params.teamId;
264
- * // ^ string
265
- * }
266
- **/
267
- params: Params;
268
- /**
269
- * This is the context passed in to your server adapter's getLoadContext() function.
270
- * It's a way to bridge the gap between the adapter's request/response API with your React Router app.
271
- * It is only applicable if you are using a custom server adapter.
272
- */
273
- context: Context;
274
- }
275
- /**
276
- * Route middleware `next` function to call downstream handlers and then complete
277
- * middlewares from the bottom-up
278
- */
279
- interface unstable_MiddlewareNextFunction<Result = unknown> {
280
- (): MaybePromise<Result>;
281
- }
282
- /**
283
- * Route middleware function signature. Receives the same "data" arguments as a
284
- * `loader`/`action` (`request`, `params`, `context`) as the first parameter and
285
- * a `next` function as the second parameter which will call downstream handlers
286
- * and then complete middlewares from the bottom-up
287
- */
288
- type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<unstable_RouterContextProvider>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
289
- /**
290
- * Arguments passed to loader functions
291
- */
292
- interface LoaderFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
293
- }
294
- /**
295
- * Arguments passed to action functions
296
- */
297
- interface ActionFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
298
- }
299
- /**
300
- * Loaders and actions can return anything
301
- */
302
- type DataFunctionValue = unknown;
303
- type DataFunctionReturnValue = MaybePromise<DataFunctionValue>;
304
- /**
305
- * Route loader function signature
306
- */
307
- type LoaderFunction<Context = DefaultContext> = {
308
- (args: LoaderFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
309
- } & {
310
- hydrate?: boolean;
311
- };
312
- /**
313
- * Route action function signature
314
- */
315
- interface ActionFunction<Context = DefaultContext> {
316
- (args: ActionFunctionArgs<Context>, handlerCtx?: unknown): DataFunctionReturnValue;
317
- }
318
- /**
319
- * Arguments passed to shouldRevalidate function
320
- */
321
- interface ShouldRevalidateFunctionArgs {
322
- /** 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. */
323
- currentUrl: URL;
324
- /** 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. */
325
- currentParams: AgnosticDataRouteMatch["params"];
326
- /** 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. */
327
- nextUrl: URL;
328
- /** 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. */
329
- nextParams: AgnosticDataRouteMatch["params"];
330
- /** The method (probably `"GET"` or `"POST"`) used in the form submission that triggered the revalidation. */
331
- formMethod?: Submission["formMethod"];
332
- /** The form action (`<Form action="/somewhere">`) that triggered the revalidation. */
333
- formAction?: Submission["formAction"];
334
- /** The form encType (`<Form encType="application/x-www-form-urlencoded">) used in the form submission that triggered the revalidation*/
335
- formEncType?: Submission["formEncType"];
336
- /** The form submission data when the form's encType is `text/plain` */
337
- text?: Submission["text"];
338
- /** The form submission data when the form's encType is `application/x-www-form-urlencoded` or `multipart/form-data` */
339
- formData?: Submission["formData"];
340
- /** The form submission data when the form's encType is `application/json` */
341
- json?: Submission["json"];
342
- /** The status code of the action response */
343
- actionStatus?: number;
344
- /**
345
- * 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.
346
- *
347
- * @example
348
- * export async function action() {
349
- * await saveSomeStuff();
350
- * return { ok: true };
351
- * }
352
- *
353
- * export function shouldRevalidate({
354
- * actionResult,
355
- * }) {
356
- * if (actionResult?.ok) {
357
- * return false;
358
- * }
359
- * return true;
360
- * }
361
- */
362
- actionResult?: any;
363
- /**
364
- * 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:
365
- *
366
- * /projects/123/tasks/abc
367
- * /projects/123/tasks/def
368
- * React Router will only call the loader for tasks/def because the param for projects/123 didn't change.
369
- *
370
- * 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.
371
- */
372
- defaultShouldRevalidate: boolean;
373
- }
374
- /**
375
- * Route shouldRevalidate function signature. This runs after any submission
376
- * (navigation or fetcher), so we flatten the navigation/fetcher submission
377
- * onto the arguments. It shouldn't matter whether it came from a navigation
378
- * or a fetcher, what really matters is the URLs and the formData since loaders
379
- * have to re-run based on the data models that were potentially mutated.
380
- */
381
- interface ShouldRevalidateFunction {
382
- (args: ShouldRevalidateFunctionArgs): boolean;
383
- }
384
- interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
385
- /**
386
- * @private
387
- */
388
- _lazyPromises?: {
389
- middleware: Promise<void> | undefined;
390
- handler: Promise<void> | undefined;
391
- route: Promise<void> | undefined;
392
- };
393
- shouldLoad: boolean;
394
- unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
395
- unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
396
- resolve: (handlerOverride?: (handler: (ctx?: unknown) => DataFunctionReturnValue) => DataFunctionReturnValue) => Promise<DataStrategyResult>;
397
- }
398
- interface DataStrategyFunctionArgs<Context = DefaultContext> extends DataFunctionArgs<Context> {
399
- matches: DataStrategyMatch[];
400
- unstable_runClientMiddleware: (cb: DataStrategyFunction<Context>) => Promise<Record<string, DataStrategyResult>>;
401
- fetcherKey: string | null;
402
- }
403
- /**
404
- * Result from a loader or action called via dataStrategy
405
- */
406
- interface DataStrategyResult {
407
- type: "data" | "error";
408
- result: unknown;
409
- }
410
- interface DataStrategyFunction<Context = DefaultContext> {
411
- (args: DataStrategyFunctionArgs<Context>): Promise<Record<string, DataStrategyResult>>;
412
- }
413
- type AgnosticPatchRoutesOnNavigationFunctionArgs<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = {
414
- signal: AbortSignal;
415
- path: string;
416
- matches: M[];
417
- fetcherKey: string | undefined;
418
- patch: (routeId: string | null, children: O[]) => void;
419
- };
420
- type AgnosticPatchRoutesOnNavigationFunction<O extends AgnosticRouteObject = AgnosticRouteObject, M extends AgnosticRouteMatch = AgnosticRouteMatch> = (opts: AgnosticPatchRoutesOnNavigationFunctionArgs<O, M>) => MaybePromise<void>;
421
- /**
422
- * Function provided by the framework-aware layers to set any framework-specific
423
- * properties from framework-agnostic properties
424
- */
425
- interface MapRoutePropertiesFunction {
426
- (route: AgnosticRouteObject): {
427
- hasErrorBoundary: boolean;
428
- } & Record<string, any>;
429
- }
430
- /**
431
- * Keys we cannot change from within a lazy object. We spread all other keys
432
- * onto the route. Either they're meaningful to the router, or they'll get
433
- * ignored.
434
- */
435
- type UnsupportedLazyRouteObjectKey = "lazy" | "caseSensitive" | "path" | "id" | "index" | "children";
436
- /**
437
- * Keys we cannot change from within a lazy() function. We spread all other keys
438
- * onto the route. Either they're meaningful to the router, or they'll get
439
- * ignored.
440
- */
441
- type UnsupportedLazyRouteFunctionKey = UnsupportedLazyRouteObjectKey | "unstable_middleware";
442
- /**
443
- * lazy object to load route properties, which can add non-matching
444
- * related properties to a route
445
- */
446
- type LazyRouteObject<R extends AgnosticRouteObject> = {
447
- [K in keyof R as K extends UnsupportedLazyRouteObjectKey ? never : K]?: () => Promise<R[K] | null | undefined>;
448
- };
449
- /**
450
- * lazy() function to load a route definition, which can add non-matching
451
- * related properties to a route
452
- */
453
- interface LazyRouteFunction<R extends AgnosticRouteObject> {
454
- (): Promise<Omit<R, UnsupportedLazyRouteFunctionKey> & Partial<Record<UnsupportedLazyRouteFunctionKey, never>>>;
455
- }
456
- type LazyRouteDefinition<R extends AgnosticRouteObject> = LazyRouteObject<R> | LazyRouteFunction<R>;
457
- /**
458
- * Base RouteObject with common props shared by all types of routes
459
- */
460
- type AgnosticBaseRouteObject = {
461
- caseSensitive?: boolean;
462
- path?: string;
463
- id?: string;
464
- unstable_middleware?: unstable_MiddlewareFunction[];
465
- loader?: LoaderFunction | boolean;
466
- action?: ActionFunction | boolean;
467
- hasErrorBoundary?: boolean;
468
- shouldRevalidate?: ShouldRevalidateFunction;
469
- handle?: any;
470
- lazy?: LazyRouteDefinition<AgnosticBaseRouteObject>;
471
- };
472
- /**
473
- * Index routes must not have children
474
- */
475
- type AgnosticIndexRouteObject = AgnosticBaseRouteObject & {
476
- children?: undefined;
477
- index: true;
478
- };
479
- /**
480
- * Non-index routes may have children, but cannot have index
481
- */
482
- type AgnosticNonIndexRouteObject = AgnosticBaseRouteObject & {
483
- children?: AgnosticRouteObject[];
484
- index?: false;
485
- };
486
- /**
487
- * A route object represents a logical route, with (optionally) its child
488
- * routes organized in a tree-like structure.
489
- */
490
- type AgnosticRouteObject = AgnosticIndexRouteObject | AgnosticNonIndexRouteObject;
491
- type AgnosticDataIndexRouteObject = AgnosticIndexRouteObject & {
492
- id: string;
493
- };
494
- type AgnosticDataNonIndexRouteObject = AgnosticNonIndexRouteObject & {
495
- children?: AgnosticDataRouteObject[];
496
- id: string;
497
- };
498
- /**
499
- * A data route object, which is just a RouteObject with a required unique ID
500
- */
501
- type AgnosticDataRouteObject = AgnosticDataIndexRouteObject | AgnosticDataNonIndexRouteObject;
502
- /**
503
- * The parameters that were parsed from the URL path.
504
- */
505
- type Params<Key extends string = string> = {
506
- readonly [key in Key]: string | undefined;
507
- };
508
- /**
509
- * A RouteMatch contains info about how a route matched a URL.
510
- */
511
- interface AgnosticRouteMatch<ParamKey extends string = string, RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject> {
512
- /**
513
- * The names and values of dynamic parameters in the URL.
514
- */
515
- params: Params<ParamKey>;
516
- /**
517
- * The portion of the URL pathname that was matched.
518
- */
519
- pathname: string;
520
- /**
521
- * The portion of the URL pathname that was matched before child routes.
522
- */
523
- pathnameBase: string;
524
- /**
525
- * The route object that was used to match.
526
- */
527
- route: RouteObjectType;
528
- }
529
- interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticDataRouteObject> {
530
- }
531
- /**
532
- * Matches the given routes to a location and returns the match data.
533
- *
534
- * @category Utils
535
- */
536
- declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
537
- interface UIMatch<Data = unknown, Handle = unknown> {
538
- id: string;
539
- pathname: string;
540
- /**
541
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
542
- **/
543
- params: AgnosticRouteMatch["params"];
544
- /** The return value from the matched route's loader or clientLoader */
545
- data: Data;
546
- /** The {@link https://reactrouter.com/start/framework/route-module#handle handle object} exported from the matched route module */
547
- handle: Handle;
548
- }
549
- declare class DataWithResponseInit<D> {
550
- type: string;
551
- data: D;
552
- init: ResponseInit | null;
553
- constructor(data: D, init?: ResponseInit);
554
- }
555
- /**
556
- * Create "responses" that contain `status`/`headers` without forcing
557
- * serialization into an actual `Response` - used by Remix single fetch
558
- *
559
- * @category Utils
560
- */
561
- declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
562
- type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
563
- /**
564
- * A redirect response. Sets the status code and the `Location` header.
565
- * Defaults to "302 Found".
566
- *
567
- * @category Utils
568
- */
569
- declare const redirect: RedirectFunction;
570
- /**
571
- * A redirect response that will force a document reload to the new location.
572
- * Sets the status code and the `Location` header.
573
- * Defaults to "302 Found".
574
- *
575
- * @category Utils
576
- */
577
- declare const redirectDocument: RedirectFunction;
578
- /**
579
- * A redirect response that will perform a `history.replaceState` instead of a
580
- * `history.pushState` for client-side navigation redirects.
581
- * Sets the status code and the `Location` header.
582
- * Defaults to "302 Found".
583
- *
584
- * @category Utils
585
- */
586
- declare const replace: RedirectFunction;
587
-
588
- /**
589
- * A Router instance manages all navigation and data loading/mutations
590
- */
591
- interface Router {
592
- /**
593
- * @private
594
- * PRIVATE - DO NOT USE
595
- *
596
- * Return the basename for the router
597
- */
598
- get basename(): RouterInit["basename"];
599
- /**
600
- * @private
601
- * PRIVATE - DO NOT USE
602
- *
603
- * Return the future config for the router
604
- */
605
- get future(): FutureConfig;
606
- /**
607
- * @private
608
- * PRIVATE - DO NOT USE
609
- *
610
- * Return the current state of the router
611
- */
612
- get state(): RouterState;
613
- /**
614
- * @private
615
- * PRIVATE - DO NOT USE
616
- *
617
- * Return the routes for this router instance
618
- */
619
- get routes(): AgnosticDataRouteObject[];
620
- /**
621
- * @private
622
- * PRIVATE - DO NOT USE
623
- *
624
- * Return the window associated with the router
625
- */
626
- get window(): RouterInit["window"];
627
- /**
628
- * @private
629
- * PRIVATE - DO NOT USE
630
- *
631
- * Initialize the router, including adding history listeners and kicking off
632
- * initial data fetches. Returns a function to cleanup listeners and abort
633
- * any in-progress loads
634
- */
635
- initialize(): Router;
636
- /**
637
- * @private
638
- * PRIVATE - DO NOT USE
639
- *
640
- * Subscribe to router.state updates
641
- *
642
- * @param fn function to call with the new state
643
- */
644
- subscribe(fn: RouterSubscriber): () => void;
645
- /**
646
- * @private
647
- * PRIVATE - DO NOT USE
648
- *
649
- * Enable scroll restoration behavior in the router
650
- *
651
- * @param savedScrollPositions Object that will manage positions, in case
652
- * it's being restored from sessionStorage
653
- * @param getScrollPosition Function to get the active Y scroll position
654
- * @param getKey Function to get the key to use for restoration
655
- */
656
- enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
657
- /**
658
- * @private
659
- * PRIVATE - DO NOT USE
660
- *
661
- * Navigate forward/backward in the history stack
662
- * @param to Delta to move in the history stack
663
- */
664
- navigate(to: number): Promise<void>;
665
- /**
666
- * Navigate to the given path
667
- * @param to Path to navigate to
668
- * @param opts Navigation options (method, submission, etc.)
669
- */
670
- navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
671
- /**
672
- * @private
673
- * PRIVATE - DO NOT USE
674
- *
675
- * Trigger a fetcher load/submission
676
- *
677
- * @param key Fetcher key
678
- * @param routeId Route that owns the fetcher
679
- * @param href href to fetch
680
- * @param opts Fetcher options, (method, submission, etc.)
681
- */
682
- fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): Promise<void>;
683
- /**
684
- * @private
685
- * PRIVATE - DO NOT USE
686
- *
687
- * Trigger a revalidation of all current route loaders and fetcher loads
688
- */
689
- revalidate(): Promise<void>;
690
- /**
691
- * @private
692
- * PRIVATE - DO NOT USE
693
- *
694
- * Utility function to create an href for the given location
695
- * @param location
696
- */
697
- createHref(location: Location | URL): string;
698
- /**
699
- * @private
700
- * PRIVATE - DO NOT USE
701
- *
702
- * Utility function to URL encode a destination path according to the internal
703
- * history implementation
704
- * @param to
705
- */
706
- encodeLocation(to: To): Path;
707
- /**
708
- * @private
709
- * PRIVATE - DO NOT USE
710
- *
711
- * Get/create a fetcher for the given key
712
- * @param key
713
- */
714
- getFetcher<TData = any>(key: string): Fetcher<TData>;
715
- /**
716
- * @private
717
- * PRIVATE - DO NOT USE
718
- *
719
- * Delete the fetcher for a given key
720
- * @param key
721
- */
722
- deleteFetcher(key: string): void;
723
- /**
724
- * @private
725
- * PRIVATE - DO NOT USE
726
- *
727
- * Cleanup listeners and abort any in-progress loads
728
- */
729
- dispose(): void;
730
- /**
731
- * @private
732
- * PRIVATE - DO NOT USE
733
- *
734
- * Get a navigation blocker
735
- * @param key The identifier for the blocker
736
- * @param fn The blocker function implementation
737
- */
738
- getBlocker(key: string, fn: BlockerFunction): Blocker;
739
- /**
740
- * @private
741
- * PRIVATE - DO NOT USE
742
- *
743
- * Delete a navigation blocker
744
- * @param key The identifier for the blocker
745
- */
746
- deleteBlocker(key: string): void;
747
- /**
748
- * @private
749
- * PRIVATE DO NOT USE
750
- *
751
- * Patch additional children routes into an existing parent route
752
- * @param routeId The parent route id or a callback function accepting `patch`
753
- * to perform batch patching
754
- * @param children The additional children routes
755
- * @param unstable_allowElementMutations Allow mutation or route elements on
756
- * existing routes. Intended for RSC-usage
757
- * only.
758
- */
759
- patchRoutes(routeId: string | null, children: AgnosticRouteObject[], unstable_allowElementMutations?: boolean): void;
760
- /**
761
- * @private
762
- * PRIVATE - DO NOT USE
763
- *
764
- * HMR needs to pass in-flight route updates to React Router
765
- * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
766
- */
767
- _internalSetRoutes(routes: AgnosticRouteObject[]): void;
768
- /**
769
- * @private
770
- * PRIVATE - DO NOT USE
771
- *
772
- * Cause subscribers to re-render. This is used to force a re-render.
773
- */
774
- _internalSetStateDoNotUseOrYouWillBreakYourApp(state: Partial<RouterState>): void;
775
- /**
776
- * @private
777
- * PRIVATE - DO NOT USE
778
- *
779
- * Internal fetch AbortControllers accessed by unit tests
780
- */
781
- _internalFetchControllers: Map<string, AbortController>;
782
- }
783
- /**
784
- * State maintained internally by the router. During a navigation, all states
785
- * reflect the "old" location unless otherwise noted.
786
- */
787
- interface RouterState {
788
- /**
789
- * The action of the most recent navigation
790
- */
791
- historyAction: Action;
792
- /**
793
- * The current location reflected by the router
794
- */
795
- location: Location;
796
- /**
797
- * The current set of route matches
798
- */
799
- matches: AgnosticDataRouteMatch[];
800
- /**
801
- * Tracks whether we've completed our initial data load
802
- */
803
- initialized: boolean;
804
- /**
805
- * Current scroll position we should start at for a new view
806
- * - number -> scroll position to restore to
807
- * - false -> do not restore scroll at all (used during submissions)
808
- * - null -> don't have a saved position, scroll to hash or top of page
809
- */
810
- restoreScrollPosition: number | false | null;
811
- /**
812
- * Indicate whether this navigation should skip resetting the scroll position
813
- * if we are unable to restore the scroll position
814
- */
815
- preventScrollReset: boolean;
816
- /**
817
- * Tracks the state of the current navigation
818
- */
819
- navigation: Navigation;
820
- /**
821
- * Tracks any in-progress revalidations
822
- */
823
- revalidation: RevalidationState;
824
- /**
825
- * Data from the loaders for the current matches
826
- */
827
- loaderData: RouteData;
828
- /**
829
- * Data from the action for the current matches
830
- */
831
- actionData: RouteData | null;
832
- /**
833
- * Errors caught from loaders for the current matches
834
- */
835
- errors: RouteData | null;
836
- /**
837
- * Map of current fetchers
838
- */
839
- fetchers: Map<string, Fetcher>;
840
- /**
841
- * Map of current blockers
842
- */
843
- blockers: Map<string, Blocker>;
844
- }
845
- /**
846
- * Data that can be passed into hydrate a Router from SSR
847
- */
848
- type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
849
- /**
850
- * Future flags to toggle new feature behavior
851
- */
852
- interface FutureConfig {
853
- unstable_middleware: boolean;
854
- }
855
- /**
856
- * Initialization options for createRouter
857
- */
858
- interface RouterInit {
859
- routes: AgnosticRouteObject[];
860
- history: History;
861
- basename?: string;
862
- unstable_getContext?: () => MaybePromise<unstable_InitialContext>;
863
- mapRouteProperties?: MapRoutePropertiesFunction;
864
- future?: Partial<FutureConfig>;
865
- hydrationRouteProperties?: string[];
866
- hydrationData?: HydrationState;
867
- window?: Window;
868
- dataStrategy?: DataStrategyFunction;
869
- patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
870
- }
871
- /**
872
- * State returned from a server-side query() call
873
- */
874
- interface StaticHandlerContext {
875
- basename: Router["basename"];
876
- location: RouterState["location"];
877
- matches: RouterState["matches"];
878
- loaderData: RouterState["loaderData"];
879
- actionData: RouterState["actionData"];
880
- errors: RouterState["errors"];
881
- statusCode: number;
882
- loaderHeaders: Record<string, Headers>;
883
- actionHeaders: Record<string, Headers>;
884
- _deepestRenderedBoundaryId?: string | null;
885
- }
886
- /**
887
- * A StaticHandler instance manages a singular SSR navigation/fetch event
888
- */
889
- interface StaticHandler {
890
- dataRoutes: AgnosticDataRouteObject[];
891
- query(request: Request, opts?: {
892
- requestContext?: unknown;
893
- filterMatchesToLoad?: (match: AgnosticDataRouteMatch) => boolean;
894
- skipLoaderErrorBubbling?: boolean;
895
- skipRevalidation?: boolean;
896
- dataStrategy?: DataStrategyFunction<unknown>;
897
- unstable_respond?: (staticContext: StaticHandlerContext) => MaybePromise<Response>;
898
- }): Promise<StaticHandlerContext | Response>;
899
- queryRoute(request: Request, opts?: {
900
- routeId?: string;
901
- requestContext?: unknown;
902
- dataStrategy?: DataStrategyFunction<unknown>;
903
- unstable_respond?: (res: Response) => MaybePromise<Response>;
904
- }): Promise<any>;
905
- }
906
- type ViewTransitionOpts = {
907
- currentLocation: Location;
908
- nextLocation: Location;
909
- };
910
- /**
911
- * Subscriber function signature for changes to router state
912
- */
913
- interface RouterSubscriber {
914
- (state: RouterState, opts: {
915
- deletedFetchers: string[];
916
- viewTransitionOpts?: ViewTransitionOpts;
917
- flushSync: boolean;
918
- }): void;
919
- }
920
- /**
921
- * Function signature for determining the key to be used in scroll restoration
922
- * for a given location
923
- */
924
- interface GetScrollRestorationKeyFunction {
925
- (location: Location, matches: UIMatch[]): string | null;
926
- }
927
- /**
928
- * Function signature for determining the current scroll position
929
- */
930
- interface GetScrollPositionFunction {
931
- (): number;
932
- }
933
- /**
934
- - "route": relative to the route hierarchy so `..` means remove all segments of the current route even if it has many. For example, a `route("posts/:id")` would have both `:id` and `posts` removed from the url.
935
- - "path": relative to the pathname so `..` means remove one segment of the pathname. For example, a `route("posts/:id")` would have only `:id` removed from the url.
936
- */
937
- type RelativeRoutingType = "route" | "path";
938
- type BaseNavigateOrFetchOptions = {
939
- preventScrollReset?: boolean;
940
- relative?: RelativeRoutingType;
941
- flushSync?: boolean;
942
- };
943
- type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
944
- replace?: boolean;
945
- state?: any;
946
- fromRouteId?: string;
947
- viewTransition?: boolean;
948
- };
949
- type BaseSubmissionOptions = {
950
- formMethod?: HTMLFormMethod;
951
- formEncType?: FormEncType;
952
- } & ({
953
- formData: FormData;
954
- body?: undefined;
955
- } | {
956
- formData?: undefined;
957
- body: any;
958
- });
959
- /**
960
- * Options for a navigate() call for a normal (non-submission) navigation
961
- */
962
- type LinkNavigateOptions = BaseNavigateOptions;
963
- /**
964
- * Options for a navigate() call for a submission navigation
965
- */
966
- type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
967
- /**
968
- * Options to pass to navigate() for a navigation
969
- */
970
- type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
971
- /**
972
- * Options for a fetch() load
973
- */
974
- type LoadFetchOptions = BaseNavigateOrFetchOptions;
975
- /**
976
- * Options for a fetch() submission
977
- */
978
- type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
979
- /**
980
- * Options to pass to fetch()
981
- */
982
- type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
983
- /**
984
- * Potential states for state.navigation
985
- */
986
- type NavigationStates = {
987
- Idle: {
988
- state: "idle";
989
- location: undefined;
990
- formMethod: undefined;
991
- formAction: undefined;
992
- formEncType: undefined;
993
- formData: undefined;
994
- json: undefined;
995
- text: undefined;
996
- };
997
- Loading: {
998
- state: "loading";
999
- location: Location;
1000
- formMethod: Submission["formMethod"] | undefined;
1001
- formAction: Submission["formAction"] | undefined;
1002
- formEncType: Submission["formEncType"] | undefined;
1003
- formData: Submission["formData"] | undefined;
1004
- json: Submission["json"] | undefined;
1005
- text: Submission["text"] | undefined;
1006
- };
1007
- Submitting: {
1008
- state: "submitting";
1009
- location: Location;
1010
- formMethod: Submission["formMethod"];
1011
- formAction: Submission["formAction"];
1012
- formEncType: Submission["formEncType"];
1013
- formData: Submission["formData"];
1014
- json: Submission["json"];
1015
- text: Submission["text"];
1016
- };
1017
- };
1018
- type Navigation = NavigationStates[keyof NavigationStates];
1019
- type RevalidationState = "idle" | "loading";
1020
- /**
1021
- * Potential states for fetchers
1022
- */
1023
- type FetcherStates<TData = any> = {
1024
- /**
1025
- * The fetcher is not calling a loader or action
1026
- *
1027
- * ```tsx
1028
- * fetcher.state === "idle"
1029
- * ```
1030
- */
1031
- Idle: {
1032
- state: "idle";
1033
- formMethod: undefined;
1034
- formAction: undefined;
1035
- formEncType: undefined;
1036
- text: undefined;
1037
- formData: undefined;
1038
- json: undefined;
1039
- /**
1040
- * If the fetcher has never been called, this will be undefined.
1041
- */
1042
- data: TData | undefined;
1043
- };
1044
- /**
1045
- * The fetcher is loading data from a {@link LoaderFunction | loader} from a
1046
- * call to {@link FetcherWithComponents.load | `fetcher.load`}.
1047
- *
1048
- * ```tsx
1049
- * // somewhere
1050
- * <button onClick={() => fetcher.load("/some/route") }>Load</button>
1051
- *
1052
- * // the state will update
1053
- * fetcher.state === "loading"
1054
- * ```
1055
- */
1056
- Loading: {
1057
- state: "loading";
1058
- formMethod: Submission["formMethod"] | undefined;
1059
- formAction: Submission["formAction"] | undefined;
1060
- formEncType: Submission["formEncType"] | undefined;
1061
- text: Submission["text"] | undefined;
1062
- formData: Submission["formData"] | undefined;
1063
- json: Submission["json"] | undefined;
1064
- data: TData | undefined;
1065
- };
1066
- /**
1067
- The fetcher is submitting to a {@link LoaderFunction} (GET) or {@link ActionFunction} (POST) from a {@link FetcherWithComponents.Form | `fetcher.Form`} or {@link FetcherWithComponents.submit | `fetcher.submit`}.
1068
-
1069
- ```tsx
1070
- // somewhere
1071
- <input
1072
- onChange={e => {
1073
- fetcher.submit(event.currentTarget.form, { method: "post" });
1074
- }}
1075
- />
1076
-
1077
- // the state will update
1078
- fetcher.state === "submitting"
1079
-
1080
- // and formData will be available
1081
- fetcher.formData
1082
- ```
1083
- */
1084
- Submitting: {
1085
- state: "submitting";
1086
- formMethod: Submission["formMethod"];
1087
- formAction: Submission["formAction"];
1088
- formEncType: Submission["formEncType"];
1089
- text: Submission["text"];
1090
- formData: Submission["formData"];
1091
- json: Submission["json"];
1092
- data: TData | undefined;
1093
- };
1094
- };
1095
- type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
1096
- interface BlockerBlocked {
1097
- state: "blocked";
1098
- reset(): void;
1099
- proceed(): void;
1100
- location: Location;
1101
- }
1102
- interface BlockerUnblocked {
1103
- state: "unblocked";
1104
- reset: undefined;
1105
- proceed: undefined;
1106
- location: undefined;
1107
- }
1108
- interface BlockerProceeding {
1109
- state: "proceeding";
1110
- reset: undefined;
1111
- proceed: undefined;
1112
- location: Location;
1113
- }
1114
- type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
1115
- type BlockerFunction = (args: {
1116
- currentLocation: Location;
1117
- nextLocation: Location;
1118
- historyAction: Action;
1119
- }) => boolean;
1120
- interface CreateStaticHandlerOptions {
1121
- basename?: string;
1122
- mapRouteProperties?: MapRoutePropertiesFunction;
1123
- future?: {};
1124
- }
1125
- declare function createStaticHandler(routes: AgnosticRouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
1126
-
1127
- interface IndexRouteObject {
1128
- caseSensitive?: AgnosticIndexRouteObject["caseSensitive"];
1129
- path?: AgnosticIndexRouteObject["path"];
1130
- id?: AgnosticIndexRouteObject["id"];
1131
- unstable_middleware?: AgnosticIndexRouteObject["unstable_middleware"];
1132
- loader?: AgnosticIndexRouteObject["loader"];
1133
- action?: AgnosticIndexRouteObject["action"];
1134
- hasErrorBoundary?: AgnosticIndexRouteObject["hasErrorBoundary"];
1135
- shouldRevalidate?: AgnosticIndexRouteObject["shouldRevalidate"];
1136
- handle?: AgnosticIndexRouteObject["handle"];
1137
- index: true;
1138
- children?: undefined;
1139
- element?: React.ReactNode | null;
1140
- hydrateFallbackElement?: React.ReactNode | null;
1141
- errorElement?: React.ReactNode | null;
1142
- Component?: React.ComponentType | null;
1143
- HydrateFallback?: React.ComponentType | null;
1144
- ErrorBoundary?: React.ComponentType | null;
1145
- lazy?: LazyRouteDefinition<RouteObject>;
1146
- }
1147
- interface NonIndexRouteObject {
1148
- caseSensitive?: AgnosticNonIndexRouteObject["caseSensitive"];
1149
- path?: AgnosticNonIndexRouteObject["path"];
1150
- id?: AgnosticNonIndexRouteObject["id"];
1151
- unstable_middleware?: AgnosticNonIndexRouteObject["unstable_middleware"];
1152
- loader?: AgnosticNonIndexRouteObject["loader"];
1153
- action?: AgnosticNonIndexRouteObject["action"];
1154
- hasErrorBoundary?: AgnosticNonIndexRouteObject["hasErrorBoundary"];
1155
- shouldRevalidate?: AgnosticNonIndexRouteObject["shouldRevalidate"];
1156
- handle?: AgnosticNonIndexRouteObject["handle"];
1157
- index?: false;
1158
- children?: RouteObject[];
1159
- element?: React.ReactNode | null;
1160
- hydrateFallbackElement?: React.ReactNode | null;
1161
- errorElement?: React.ReactNode | null;
1162
- Component?: React.ComponentType | null;
1163
- HydrateFallback?: React.ComponentType | null;
1164
- ErrorBoundary?: React.ComponentType | null;
1165
- lazy?: LazyRouteDefinition<RouteObject>;
1166
- }
1167
- type RouteObject = IndexRouteObject | NonIndexRouteObject;
1168
- type DataRouteObject = RouteObject & {
1169
- children?: DataRouteObject[];
1170
- id: string;
1171
- };
1172
- interface RouteMatch<ParamKey extends string = string, RouteObjectType extends RouteObject = RouteObject> extends AgnosticRouteMatch<ParamKey, RouteObjectType> {
1173
- }
1174
- interface DataRouteMatch extends RouteMatch<string, DataRouteObject> {
1175
- }
1176
-
1177
- type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1178
- type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1179
- interface HtmlLinkProps {
1180
- /**
1181
- * Address of the hyperlink
1182
- */
1183
- href?: string;
1184
- /**
1185
- * How the element handles crossorigin requests
1186
- */
1187
- crossOrigin?: "anonymous" | "use-credentials";
1188
- /**
1189
- * Relationship between the document containing the hyperlink and the destination resource
1190
- */
1191
- rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
1192
- /**
1193
- * Applicable media: "screen", "print", "(max-width: 764px)"
1194
- */
1195
- media?: string;
1196
- /**
1197
- * Integrity metadata used in Subresource Integrity checks
1198
- */
1199
- integrity?: string;
1200
- /**
1201
- * Language of the linked resource
1202
- */
1203
- hrefLang?: string;
1204
- /**
1205
- * Hint for the type of the referenced resource
1206
- */
1207
- type?: string;
1208
- /**
1209
- * Referrer policy for fetches initiated by the element
1210
- */
1211
- referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
1212
- /**
1213
- * Sizes of the icons (for rel="icon")
1214
- */
1215
- sizes?: string;
1216
- /**
1217
- * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1218
- */
1219
- as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
1220
- /**
1221
- * Color to use when customizing a site's icon (for rel="mask-icon")
1222
- */
1223
- color?: string;
1224
- /**
1225
- * Whether the link is disabled
1226
- */
1227
- disabled?: boolean;
1228
- /**
1229
- * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
1230
- */
1231
- title?: string;
1232
- /**
1233
- * Images to use in different situations, e.g., high-resolution displays,
1234
- * small monitors, etc. (for rel="preload")
1235
- */
1236
- imageSrcSet?: string;
1237
- /**
1238
- * Image sizes for different page layouts (for rel="preload")
1239
- */
1240
- imageSizes?: string;
1241
- }
1242
- interface HtmlLinkPreloadImage extends HtmlLinkProps {
1243
- /**
1244
- * Relationship between the document containing the hyperlink and the destination resource
1245
- */
1246
- rel: "preload";
1247
- /**
1248
- * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1249
- */
1250
- as: "image";
1251
- /**
1252
- * Address of the hyperlink
1253
- */
1254
- href?: string;
1255
- /**
1256
- * Images to use in different situations, e.g., high-resolution displays,
1257
- * small monitors, etc. (for rel="preload")
1258
- */
1259
- imageSrcSet: string;
1260
- /**
1261
- * Image sizes for different page layouts (for rel="preload")
1262
- */
1263
- imageSizes?: string;
1264
- }
1265
- /**
1266
- * Represents a `<link>` element.
1267
- *
1268
- * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
1269
- */
1270
- type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
1271
- imageSizes?: never;
1272
- });
1273
- interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1274
- /**
1275
- * The absolute path of the page to prefetch.
1276
- */
1277
- page: string;
1278
- }
1279
- type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1280
-
1281
- type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1282
- [key: PropertyKey]: Serializable;
1283
- } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
1284
-
1285
- /**
1286
- * A brand that can be applied to a type to indicate that it will serialize
1287
- * to a specific type when transported to the client from a loader.
1288
- * Only use this if you have additional serialization/deserialization logic
1289
- * in your application.
1290
- */
1291
- type unstable_SerializesTo<T> = {
1292
- unstable__ReactRouter_SerializesTo: [T];
1293
- };
1294
-
1295
- type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
1296
- type IsAny<T> = 0 extends 1 & T ? true : false;
1297
- type Func = (...args: any[]) => unknown;
1298
-
1299
- 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 Set<infer U> ? Set<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> ? {
1300
- [K in keyof T]: Serialize<T[K]>;
1301
- } : undefined;
1302
- type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1303
- type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1304
- type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1305
- type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1306
- type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1307
- type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1308
- type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [ClientLoaderFunctionArgs | ClientActionFunctionArgs] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1309
-
1310
- /**
1311
- * A function that handles data mutations for a route on the client
1312
- */
1313
- type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
1314
- /**
1315
- * Arguments passed to a route `clientAction` function
1316
- */
1317
- type ClientActionFunctionArgs = ActionFunctionArgs & {
1318
- serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1319
- };
1320
- /**
1321
- * A function that loads data for a route on the client
1322
- */
1323
- type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
1324
- hydrate?: boolean;
1325
- };
1326
- /**
1327
- * Arguments passed to a route `clientLoader` function
1328
- */
1329
- type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1330
- serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1331
- };
1332
- type HeadersArgs = {
1333
- loaderHeaders: Headers;
1334
- parentHeaders: Headers;
1335
- actionHeaders: Headers;
1336
- errorHeaders: Headers | undefined;
1337
- };
1338
- /**
1339
- * A function that returns HTTP headers to be used for a route. These headers
1340
- * will be merged with (and take precedence over) headers from parent routes.
1341
- */
1342
- interface HeadersFunction {
1343
- (args: HeadersArgs): Headers | HeadersInit;
1344
- }
1345
- /**
1346
- * A function that defines `<link>` tags to be inserted into the `<head>` of
1347
- * the document on route transitions.
1348
- *
1349
- * @see https://remix.run/route/meta
1350
- */
1351
- interface LinksFunction {
1352
- (): LinkDescriptor[];
1353
- }
1354
- interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1355
- id: RouteId;
1356
- pathname: DataRouteMatch["pathname"];
1357
- data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1358
- handle?: RouteHandle;
1359
- params: DataRouteMatch["params"];
1360
- meta: MetaDescriptor[];
1361
- error?: unknown;
1362
- }
1363
- type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
1364
- [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1365
- }[keyof MatchLoaders]>;
1366
- interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1367
- data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1368
- params: Params;
1369
- location: Location;
1370
- matches: MetaMatches<MatchLoaders>;
1371
- error?: unknown;
1372
- }
1373
- /**
1374
- * A function that returns an array of data objects to use for rendering
1375
- * metadata HTML tags in a route. These tags are not rendered on descendant
1376
- * routes in the route hierarchy. In other words, they will only be rendered on
1377
- * the route in which they are exported.
1378
- *
1379
- * @param Loader - The type of the current route's loader function
1380
- * @param MatchLoaders - Mapping from a parent route's filepath to its loader
1381
- * function type
1382
- *
1383
- * Note that parent route filepaths are relative to the `app/` directory.
1384
- *
1385
- * For example, if this meta function is for `/sales/customers/$customerId`:
1386
- *
1387
- * ```ts
1388
- * // app/root.tsx
1389
- * const loader = () => ({ hello: "world" })
1390
- * export type Loader = typeof loader
1391
- *
1392
- * // app/routes/sales.tsx
1393
- * const loader = () => ({ salesCount: 1074 })
1394
- * export type Loader = typeof loader
1395
- *
1396
- * // app/routes/sales/customers.tsx
1397
- * const loader = () => ({ customerCount: 74 })
1398
- * export type Loader = typeof loader
1399
- *
1400
- * // app/routes/sales/customers/$customersId.tsx
1401
- * import type { Loader as RootLoader } from "../../../root"
1402
- * import type { Loader as SalesLoader } from "../../sales"
1403
- * import type { Loader as CustomersLoader } from "../../sales/customers"
1404
- *
1405
- * const loader = () => ({ name: "Customer name" })
1406
- *
1407
- * const meta: MetaFunction<typeof loader, {
1408
- * "root": RootLoader,
1409
- * "routes/sales": SalesLoader,
1410
- * "routes/sales/customers": CustomersLoader,
1411
- * }> = ({ data, matches }) => {
1412
- * const { name } = data
1413
- * // ^? string
1414
- * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
1415
- * // ^? number
1416
- * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
1417
- * // ^? number
1418
- * const { hello } = matches.find((match) => match.id === "root").data
1419
- * // ^? "world"
1420
- * }
1421
- * ```
1422
- */
1423
- interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1424
- (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
1425
- }
1426
- type MetaDescriptor = {
1427
- charSet: "utf-8";
1428
- } | {
1429
- title: string;
1430
- } | {
1431
- name: string;
1432
- content: string;
1433
- } | {
1434
- property: string;
1435
- content: string;
1436
- } | {
1437
- httpEquiv: string;
1438
- content: string;
1439
- } | {
1440
- "script:ld+json": LdJsonObject;
1441
- } | {
1442
- tagName: "meta" | "link";
1443
- [name: string]: string;
1444
- } | {
1445
- [name: string]: unknown;
1446
- };
1447
- type LdJsonObject = {
1448
- [Key in string]: LdJsonValue;
1449
- } & {
1450
- [Key in string]?: LdJsonValue | undefined;
1451
- };
1452
- type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
1453
- type LdJsonPrimitive = string | number | boolean | null;
1454
- type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
1455
- /**
1456
- * An arbitrary object that is associated with a route.
1457
- *
1458
- * @see https://remix.run/route/handle
1459
- */
1460
- type RouteHandle = unknown;
1461
-
1462
- type ServerRouteObjectBase = {
1463
- action?: ActionFunction;
1464
- clientAction?: ClientActionFunction;
1465
- clientLoader?: ClientLoaderFunction;
1466
- default?: React.ComponentType<any>;
1467
- ErrorBoundary?: React.ComponentType<any>;
1468
- handle?: any;
1469
- headers?: HeadersFunction;
1470
- HydrateFallback?: React.ComponentType<any>;
1471
- Layout?: React.ComponentType<any>;
1472
- links?: LinksFunction;
1473
- loader?: LoaderFunction;
1474
- meta?: MetaFunction;
1475
- shouldRevalidate?: ShouldRevalidateFunction;
1476
- };
1477
- type ServerRouteObject = ServerRouteObjectBase & {
1478
- id: string;
1479
- path?: string;
1480
- lazy?: () => Promise<ServerRouteObjectBase>;
1481
- } & ({
1482
- index: true;
1483
- } | {
1484
- children?: ServerRouteObject[];
1485
- });
1486
- type RenderedRoute = {
1487
- clientAction?: ClientActionFunction;
1488
- clientLoader?: ClientLoaderFunction;
1489
- element?: React.ReactElement | false;
1490
- errorElement?: React.ReactElement;
1491
- handle?: any;
1492
- hasAction: boolean;
1493
- hasErrorBoundary: boolean;
1494
- hasLoader: boolean;
1495
- hydrateFallbackElement?: React.ReactElement;
1496
- id: string;
1497
- index?: boolean;
1498
- links?: LinksFunction;
1499
- meta?: MetaFunction;
1500
- parentId?: string;
1501
- path?: string;
1502
- shouldRevalidate?: ShouldRevalidateFunction;
1503
- };
1504
- type ServerRouteMatch = RenderedRoute & {
1505
- params: Params;
1506
- pathname: string;
1507
- pathnameBase: string;
1508
- };
1509
- type ServerRenderPayload = {
1510
- type: "render";
1511
- actionData: Record<string, any> | null;
1512
- basename?: string;
1513
- errors: Record<string, any> | null;
1514
- loaderData: Record<string, any>;
1515
- location: Location;
1516
- matches: ServerRouteMatch[];
1517
- patches?: RenderedRoute[];
1518
- nonce?: string;
1519
- };
1520
- type ServerManifestPayload = {
1521
- type: "manifest";
1522
- matches: RenderedRoute[];
1523
- patches: RenderedRoute[];
1524
- };
1525
- type ServerActionPayload = {
1526
- type: "action";
1527
- actionResult: Promise<unknown>;
1528
- rerender?: Promise<ServerRenderPayload | ServerRedirectPayload>;
1529
- };
1530
- type ServerRedirectPayload = {
1531
- type: "redirect";
1532
- status: number;
1533
- location: string;
1534
- replace: boolean;
1535
- reload: boolean;
1536
- };
1537
- type ServerPayload = ServerRenderPayload | ServerManifestPayload | ServerActionPayload | ServerRedirectPayload;
1538
- type ServerMatch = {
1539
- statusCode: number;
1540
- headers: Headers;
1541
- payload: ServerPayload;
1542
- };
1543
- type DecodeCallServerFunction = (id: string, reply: FormData | string) => Promise<() => Promise<unknown>>;
1544
- type DecodeFormActionFunction = (formData: FormData) => Promise<() => Promise<void>>;
1545
- declare function matchRSCServerRequest({ decodeCallServer, decodeFormAction, onError, request, routes, }: {
1546
- decodeCallServer?: DecodeCallServerFunction;
1547
- decodeFormAction?: DecodeFormActionFunction;
1548
- onError?: (error: unknown) => void;
1549
- request: Request;
1550
- routes: ServerRouteObject[];
1551
- }): Promise<ServerMatch>;
1552
-
1553
- export { type DecodeCallServerFunction, type DecodeFormActionFunction, type ServerManifestPayload, type ServerMatch, type ServerPayload, type ServerRenderPayload, type RenderedRoute as ServerRouteManifest, type ServerRouteMatch, type ServerRouteObject, createStaticHandler, data, matchRSCServerRequest, matchRoutes, redirect, redirectDocument, replace };