react-router 7.7.1 → 7.8.0-pre.1

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 (66) hide show
  1. package/CHANGELOG.md +87 -5
  2. package/dist/development/browser-z32v5KVN.d.mts +46 -0
  3. package/dist/development/{chunk-R73PQUJU.js → chunk-4EVDZJGM.js} +130 -130
  4. package/dist/{production/chunk-K3SBCRK4.mjs → development/chunk-I22FVTOY.mjs} +177 -134
  5. package/dist/development/{chunk-K7YFBME3.js → chunk-NGF2R4G7.js} +285 -189
  6. package/dist/development/{chunk-C37GKA54.mjs → chunk-XFFANEXU.mjs} +266 -170
  7. package/dist/development/{components-CjQijYga.d.mts → components-CuPfnyiZ.d.mts} +33 -21
  8. package/dist/{production/route-data-CqEmXQub.d.mts → development/context-DohQKLID.d.mts} +312 -525
  9. package/dist/development/dom-export.d.mts +16 -12
  10. package/dist/development/dom-export.d.ts +13 -8
  11. package/dist/development/dom-export.js +3 -3
  12. package/dist/development/dom-export.mjs +3 -3
  13. package/dist/development/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-BzBbJLAD.d.ts} +357 -219
  14. package/dist/{production/index-react-server-client-KLg-U4nr.d.mts → development/index-react-server-client-CuajY2vy.d.mts} +327 -200
  15. package/dist/development/index-react-server-client.d.mts +4 -3
  16. package/dist/development/index-react-server-client.d.ts +2 -2
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.d.mts +291 -71
  20. package/dist/development/index-react-server.d.ts +291 -71
  21. package/dist/development/index-react-server.js +209 -182
  22. package/dist/development/index-react-server.mjs +209 -182
  23. package/dist/development/index.d.mts +294 -86
  24. package/dist/development/index.d.ts +136 -105
  25. package/dist/development/index.js +258 -215
  26. package/dist/development/index.mjs +3 -3
  27. package/dist/development/lib/types/internal.d.mts +13 -2
  28. package/dist/development/lib/types/internal.d.ts +12 -2
  29. package/dist/development/lib/types/internal.js +1 -1
  30. package/dist/development/lib/types/internal.mjs +1 -1
  31. package/dist/development/route-data-CpB5xtMm.d.mts +473 -0
  32. package/dist/{production/routeModules-BR2FO0ix.d.ts → development/routeModules-qBivMBjd.d.ts} +325 -68
  33. package/dist/production/browser-z32v5KVN.d.mts +46 -0
  34. package/dist/production/{chunk-4DGLNKXF.js → chunk-4PESVXQ2.js} +130 -130
  35. package/dist/{development/chunk-KIUJAIYX.mjs → production/chunk-JJOMWYJ4.mjs} +177 -134
  36. package/dist/production/{chunk-IZ57JD2V.mjs → chunk-P2ZJHOXZ.mjs} +266 -170
  37. package/dist/production/{chunk-7OQROU2D.js → chunk-RLJ23MYZ.js} +285 -189
  38. package/dist/production/{components-CjQijYga.d.mts → components-CuPfnyiZ.d.mts} +33 -21
  39. package/dist/{development/route-data-CqEmXQub.d.mts → production/context-DohQKLID.d.mts} +312 -525
  40. package/dist/production/dom-export.d.mts +16 -12
  41. package/dist/production/dom-export.d.ts +13 -8
  42. package/dist/production/dom-export.js +3 -3
  43. package/dist/production/dom-export.mjs +3 -3
  44. package/dist/production/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-BzBbJLAD.d.ts} +357 -219
  45. package/dist/{development/index-react-server-client-KLg-U4nr.d.mts → production/index-react-server-client-CuajY2vy.d.mts} +327 -200
  46. package/dist/production/index-react-server-client.d.mts +4 -3
  47. package/dist/production/index-react-server-client.d.ts +2 -2
  48. package/dist/production/index-react-server-client.js +4 -4
  49. package/dist/production/index-react-server-client.mjs +2 -2
  50. package/dist/production/index-react-server.d.mts +291 -71
  51. package/dist/production/index-react-server.d.ts +291 -71
  52. package/dist/production/index-react-server.js +209 -182
  53. package/dist/production/index-react-server.mjs +209 -182
  54. package/dist/production/index.d.mts +294 -86
  55. package/dist/production/index.d.ts +136 -105
  56. package/dist/production/index.js +258 -215
  57. package/dist/production/index.mjs +3 -3
  58. package/dist/production/lib/types/internal.d.mts +13 -2
  59. package/dist/production/lib/types/internal.d.ts +12 -2
  60. package/dist/production/lib/types/internal.js +1 -1
  61. package/dist/production/lib/types/internal.mjs +1 -1
  62. package/dist/production/route-data-CpB5xtMm.d.mts +473 -0
  63. package/dist/{development/routeModules-BR2FO0ix.d.ts → production/routeModules-qBivMBjd.d.ts} +325 -68
  64. package/package.json +1 -1
  65. package/dist/development/browser-7LYX59NK.d.mts +0 -226
  66. package/dist/production/browser-7LYX59NK.d.mts +0 -226
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { ComponentType, ReactElement } from 'react';
3
2
 
4
3
  /**
5
4
  * Actions represent the type of change to a location value.
@@ -271,35 +270,122 @@ type Submission = {
271
270
  json: undefined;
272
271
  text: string;
273
272
  };
273
+ /**
274
+ * A context instance used as the key for the `get`/`set` methods of a
275
+ * {@link unstable_RouterContextProvider}. Accepts an optional default
276
+ * value to be returned if no value has been set.
277
+ */
274
278
  interface unstable_RouterContext<T = unknown> {
275
279
  defaultValue?: T;
276
280
  }
277
281
  /**
278
- * Creates a context object that may be used to store and retrieve arbitrary values.
282
+ * Creates a type-safe {@link unstable_RouterContext} object that can be used to
283
+ * store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
284
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
285
+ * Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
286
+ * but specifically designed for React Router's request/response lifecycle.
287
+ *
288
+ * If a `defaultValue` is provided, it will be returned from `context.get()`
289
+ * when no value has been set for the context. Otherwise, reading this context
290
+ * when no value has been set will throw an error.
291
+ *
292
+ * ```tsx filename=app/context.ts
293
+ * import { unstable_createContext } from "react-router";
279
294
  *
280
- * If a `defaultValue` is provided, it will be returned from `context.get()` when no value has been
281
- * set for the context. Otherwise reading this context when no value has been set will throw an
282
- * error.
295
+ * // Create a context for user data
296
+ * export const userContext =
297
+ * unstable_createContext<User | null>(null);
298
+ * ```
299
+ *
300
+ * ```tsx filename=app/middleware/auth.ts
301
+ * import { getUserFromSession } from "~/auth.server";
302
+ * import { userContext } from "~/context";
303
+ *
304
+ * export const authMiddleware = async ({
305
+ * context,
306
+ * request,
307
+ * }) => {
308
+ * const user = await getUserFromSession(request);
309
+ * context.set(userContext, user);
310
+ * };
311
+ * ```
283
312
  *
284
- * @param defaultValue The default value for the context
285
- * @returns A context object
313
+ * ```tsx filename=app/routes/profile.tsx
314
+ * import { userContext } from "~/context";
315
+ *
316
+ * export async function loader({
317
+ * context,
318
+ * }: Route.LoaderArgs) {
319
+ * const user = context.get(userContext);
320
+ *
321
+ * if (!user) {
322
+ * throw new Response("Unauthorized", { status: 401 });
323
+ * }
324
+ *
325
+ * return { user };
326
+ * }
327
+ * ```
328
+ *
329
+ * @public
330
+ * @category Utils
331
+ * @mode framework
332
+ * @mode data
333
+ * @param defaultValue An optional default value for the context. This value
334
+ * will be returned if no value has been set for this context.
335
+ * @returns A {@link unstable_RouterContext} object that can be used with
336
+ * `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
337
+ * [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
286
338
  */
287
339
  declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
288
340
  /**
289
- * A Map of RouterContext objects to their initial values - used to populate a
290
- * fresh `context` value per request/navigation/fetch
291
- */
292
- type unstable_InitialContext = Map<unstable_RouterContext, unknown>;
293
- /**
294
- * Provides methods for writing/reading values in application context in a typesafe way.
341
+ * Provides methods for writing/reading values in application context in a
342
+ * type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
343
+ *
344
+ * @example
345
+ * import {
346
+ * unstable_createContext,
347
+ * unstable_RouterContextProvider
348
+ * } from "react-router";
349
+ *
350
+ * const userContext = unstable_createContext<User | null>(null);
351
+ * const contextProvider = new unstable_RouterContextProvider();
352
+ * contextProvider.set(userContext, getUser());
353
+ * // ^ Type-safe
354
+ * const user = contextProvider.get(userContext);
355
+ * // ^ User
356
+ *
357
+ * @public
358
+ * @category Utils
359
+ * @mode framework
360
+ * @mode data
295
361
  */
296
362
  declare class unstable_RouterContextProvider {
297
363
  #private;
298
- constructor(init?: unstable_InitialContext);
364
+ /**
365
+ * Create a new `unstable_RouterContextProvider` instance
366
+ * @param init An optional initial context map to populate the provider with
367
+ */
368
+ constructor(init?: Map<unstable_RouterContext, unknown>);
369
+ /**
370
+ * Access a value from the context. If no value has been set for the context,
371
+ * it will return the context's `defaultValue` if provided, or throw an error
372
+ * if no `defaultValue` was set.
373
+ * @param context The context to get the value for
374
+ * @returns The value for the context, or the context's `defaultValue` if no
375
+ * value was set
376
+ */
299
377
  get<T>(context: unstable_RouterContext<T>): T;
378
+ /**
379
+ * Set a value for the context. If the context already has a value set, this
380
+ * will overwrite it.
381
+ *
382
+ * @param context The context to set the value for
383
+ * @param value The value to set for the context
384
+ * @returns {void}
385
+ */
300
386
  set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
301
387
  }
302
- type DefaultContext = MiddlewareEnabled extends true ? unstable_RouterContextProvider : any;
388
+ type DefaultContext = MiddlewareEnabled extends true ? Readonly<unstable_RouterContextProvider> : any;
303
389
  /**
304
390
  * @private
305
391
  * Arguments passed to route loader/action functions. Same for now but we keep
@@ -321,7 +407,7 @@ interface DataFunctionArgs<Context> {
321
407
  * params.teamId;
322
408
  * // ^ string
323
409
  * }
324
- **/
410
+ */
325
411
  params: Params;
326
412
  /**
327
413
  * This is the context passed in to your server adapter's getLoadContext() function.
@@ -335,7 +421,7 @@ interface DataFunctionArgs<Context> {
335
421
  * middlewares from the bottom-up
336
422
  */
337
423
  interface unstable_MiddlewareNextFunction<Result = unknown> {
338
- (): MaybePromise<Result>;
424
+ (): Promise<Result>;
339
425
  }
340
426
  /**
341
427
  * Route middleware function signature. Receives the same "data" arguments as a
@@ -343,7 +429,7 @@ interface unstable_MiddlewareNextFunction<Result = unknown> {
343
429
  * a `next` function as the second parameter which will call downstream handlers
344
430
  * and then complete middlewares from the bottom-up
345
431
  */
346
- type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<unstable_RouterContextProvider>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
432
+ type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<unstable_RouterContextProvider>>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
347
433
  /**
348
434
  * Arguments passed to loader functions
349
435
  */
@@ -449,34 +535,39 @@ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRoute
449
535
  route: Promise<void> | undefined;
450
536
  };
451
537
  /**
452
- * A boolean value indicating whether this route handler should be called in this pass.
538
+ * A boolean value indicating whether this route handler should be called in
539
+ * this pass.
453
540
  *
454
- * The `matches` array always includes _all_ matched routes even when only _some_
455
- * route handlers need to be called so that things like middleware can be implemented.
541
+ * The `matches` array always includes _all_ matched routes even when only
542
+ * _some_ route handlers need to be called so that things like middleware can
543
+ * be implemented.
456
544
  *
457
- * `shouldLoad` is usually only interesting if you are skipping the route handler
458
- * entirely and implementing custom handler logic - since it lets you determine
459
- * if that custom logic should run for this route or not.
545
+ * `shouldLoad` is usually only interesting if you are skipping the route
546
+ * handler entirely and implementing custom handler logic - since it lets you
547
+ * determine if that custom logic should run for this route or not.
460
548
  *
461
549
  * For example:
462
550
  * - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
463
551
  * you'll get an array of three matches (`[parent, child, b]`), but only `b`
464
552
  * will have `shouldLoad=true` because the data for `parent` and `child` is
465
553
  * already loaded
466
- * - If you are on `/parent/child/a` and you submit to `a`'s `action`, then only
467
- * `a` will have `shouldLoad=true` for the action execution of `dataStrategy`
468
- * - After the `action`, `dataStrategy` will be called again for the `loader`
469
- * revalidation, and all matches will have `shouldLoad=true` (assuming no custom
470
- * `shouldRevalidate` implementations)
554
+ * - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
555
+ * then only `a` will have `shouldLoad=true` for the action execution of
556
+ * `dataStrategy`
557
+ * - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
558
+ * `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
559
+ * revalidation, and all matches will have `shouldLoad=true` (assuming no
560
+ * custom `shouldRevalidate` implementations)
471
561
  */
472
562
  shouldLoad: boolean;
473
563
  unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
474
564
  unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
475
565
  /**
476
566
  * An async function that will resolve any `route.lazy` implementations and
477
- * execute the route's handler (if necessary), returning a `DataStrategyResult`
567
+ * execute the route's handler (if necessary), returning a {@link DataStrategyResult}
478
568
  *
479
- * - Calling `match.resolve` does not mean you're calling the `loader`/`action`
569
+ * - Calling `match.resolve` does not mean you're calling the
570
+ * [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
480
571
  * (the "handler") - `resolve` will only call the `handler` internally if
481
572
  * needed _and_ if you don't pass your own `handlerOverride` function parameter
482
573
  * - It is safe to call `match.resolve` for all matches, even if they have
@@ -643,7 +734,28 @@ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticData
643
734
  /**
644
735
  * Matches the given routes to a location and returns the match data.
645
736
  *
737
+ * @example
738
+ * import { matchRoutes } from "react-router";
739
+ *
740
+ * let routes = [{
741
+ * path: "/",
742
+ * Component: Root,
743
+ * children: [{
744
+ * path: "dashboard",
745
+ * Component: Dashboard,
746
+ * }]
747
+ * }];
748
+ *
749
+ * matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
750
+ *
751
+ * @public
646
752
  * @category Utils
753
+ * @param routes The array of route objects to match against.
754
+ * @param locationArg The location to match against, either a string path or a
755
+ * partial {@link Location} object
756
+ * @param basename Optional base path to strip from the location before matching.
757
+ * Defaults to `/`.
758
+ * @returns An array of matched routes, or `null` if no matches were found.
647
759
  */
648
760
  declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
649
761
  interface UIMatch<Data = unknown, Handle = unknown> {
@@ -651,29 +763,53 @@ interface UIMatch<Data = unknown, Handle = unknown> {
651
763
  pathname: string;
652
764
  /**
653
765
  * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
654
- **/
766
+ */
655
767
  params: AgnosticRouteMatch["params"];
656
- /** The return value from the matched route's loader or clientLoader */
657
- data: Data;
658
- /** The {@link https://reactrouter.com/start/framework/route-module#handle handle object} exported from the matched route module */
768
+ /**
769
+ * The return value from the matched route's loader or clientLoader. This might
770
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
771
+ * an error and we're currently displaying an `ErrorBoundary`.
772
+ *
773
+ * @deprecated Use `UIMatch.loaderData` instead
774
+ */
775
+ data: Data | undefined;
776
+ /**
777
+ * The return value from the matched route's loader or clientLoader. This might
778
+ * be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
779
+ * an error and we're currently displaying an `ErrorBoundary`.
780
+ */
781
+ loaderData: Data | undefined;
782
+ /**
783
+ * The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
784
+ * exported from the matched route module
785
+ */
659
786
  handle: Handle;
660
787
  }
661
788
  /**
662
789
  * Returns a path with params interpolated.
663
790
  *
791
+ * @example
792
+ * import { generatePath } from "react-router";
793
+ *
794
+ * generatePath("/users/:id", { id: "123" }); // "/users/123"
795
+ *
796
+ * @public
664
797
  * @category Utils
798
+ * @param originalPath The original path to generate.
799
+ * @param params The parameters to interpolate into the path.
800
+ * @returns The generated path with parameters interpolated.
665
801
  */
666
802
  declare function generatePath<Path extends string>(originalPath: Path, params?: {
667
803
  [key in PathParam<Path>]: string | null;
668
804
  }): string;
669
805
  /**
670
- * A PathPattern is used to match on some portion of a URL pathname.
806
+ * Used to match on some portion of a URL pathname.
671
807
  */
672
808
  interface PathPattern<Path extends string = string> {
673
809
  /**
674
810
  * A string to match against a URL pathname. May contain `:id`-style segments
675
- * to indicate placeholders for dynamic parameters. May also end with `/*` to
676
- * indicate matching the rest of the URL pathname.
811
+ * to indicate placeholders for dynamic parameters. It May also end with `/*`
812
+ * to indicate matching the rest of the URL pathname.
677
813
  */
678
814
  path: Path;
679
815
  /**
@@ -687,7 +823,7 @@ interface PathPattern<Path extends string = string> {
687
823
  end?: boolean;
688
824
  }
689
825
  /**
690
- * A PathMatch contains info about how a PathPattern matched on a URL pathname.
826
+ * Contains info about how a {@link PathPattern} matched on a URL pathname.
691
827
  */
692
828
  interface PathMatch<ParamKey extends string = string> {
693
829
  /**
@@ -711,13 +847,26 @@ interface PathMatch<ParamKey extends string = string> {
711
847
  * Performs pattern matching on a URL pathname and returns information about
712
848
  * the match.
713
849
  *
850
+ * @public
714
851
  * @category Utils
852
+ * @param pattern The pattern to match against the URL pathname. This can be a
853
+ * string or a {@link PathPattern} object. If a string is provided, it will be
854
+ * treated as a pattern with `caseSensitive` set to `false` and `end` set to
855
+ * `true`.
856
+ * @param pathname The URL pathname to match against the pattern.
857
+ * @returns A path match object if the pattern matches the pathname,
858
+ * or `null` if it does not match.
715
859
  */
716
860
  declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
717
861
  /**
718
- * Returns a resolved path object relative to the given pathname.
862
+ * Returns a resolved {@link Path} object relative to the given pathname.
719
863
  *
864
+ * @public
720
865
  * @category Utils
866
+ * @param to The path to resolve, either a string or a partial {@link Path}
867
+ * object.
868
+ * @param fromPathname The pathname to resolve the path from. Defaults to `/`.
869
+ * @returns A {@link Path} object with the resolved pathname, search, and hash.
721
870
  */
722
871
  declare function resolvePath(to: To, fromPathname?: string): Path;
723
872
  declare class DataWithResponseInit<D> {
@@ -727,35 +876,116 @@ declare class DataWithResponseInit<D> {
727
876
  constructor(data: D, init?: ResponseInit);
728
877
  }
729
878
  /**
730
- * Create "responses" that contain `status`/`headers` without forcing
731
- * serialization into an actual `Response` - used by Remix single fetch
879
+ * Create "responses" that contain `headers`/`status` without forcing
880
+ * serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
881
+ *
882
+ * @example
883
+ * import { data } from "react-router";
884
+ *
885
+ * export async function action({ request }: Route.ActionArgs) {
886
+ * let formData = await request.formData();
887
+ * let item = await createItem(formData);
888
+ * return data(item, {
889
+ * headers: { "X-Custom-Header": "value" }
890
+ * status: 201,
891
+ * });
892
+ * }
732
893
  *
894
+ * @public
733
895
  * @category Utils
896
+ * @mode framework
897
+ * @mode data
898
+ * @param data The data to be included in the response.
899
+ * @param init The status code or a `ResponseInit` object to be included in the
900
+ * response.
901
+ * @returns A {@link DataWithResponseInit} instance containing the data and
902
+ * response init.
734
903
  */
735
904
  declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
736
905
  type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
737
906
  /**
738
- * A redirect response. Sets the status code and the `Location` header.
739
- * Defaults to "302 Found".
907
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
908
+ * Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
909
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
740
910
  *
911
+ * @example
912
+ * import { redirect } from "react-router";
913
+ *
914
+ * export async function loader({ request }: Route.LoaderArgs) {
915
+ * if (!isLoggedIn(request))
916
+ * throw redirect("/login");
917
+ * }
918
+ *
919
+ * // ...
920
+ * }
921
+ *
922
+ * @public
741
923
  * @category Utils
924
+ * @mode framework
925
+ * @mode data
926
+ * @param url The URL to redirect to.
927
+ * @param init The status code or a `ResponseInit` object to be included in the
928
+ * response.
929
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
930
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
931
+ * header.
742
932
  */
743
933
  declare const redirect: RedirectFunction;
744
934
  /**
745
- * A redirect response that will force a document reload to the new location.
746
- * Sets the status code and the `Location` header.
747
- * Defaults to "302 Found".
935
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
936
+ * that will force a document reload to the new location. Sets the status code
937
+ * and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
938
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
748
939
  *
940
+ * ```tsx filename=routes/logout.tsx
941
+ * import { redirectDocument } from "react-router";
942
+ *
943
+ * import { destroySession } from "../sessions.server";
944
+ *
945
+ * export async function action({ request }: Route.ActionArgs) {
946
+ * let session = await getSession(request.headers.get("Cookie"));
947
+ * return redirectDocument("/", {
948
+ * headers: { "Set-Cookie": await destroySession(session) }
949
+ * });
950
+ * }
951
+ * ```
952
+ *
953
+ * @public
749
954
  * @category Utils
955
+ * @mode framework
956
+ * @mode data
957
+ * @param url The URL to redirect to.
958
+ * @param init The status code or a `ResponseInit` object to be included in the
959
+ * response.
960
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
961
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
962
+ * header.
750
963
  */
751
964
  declare const redirectDocument: RedirectFunction;
752
965
  /**
753
- * A redirect response that will perform a `history.replaceState` instead of a
754
- * `history.pushState` for client-side navigation redirects.
755
- * Sets the status code and the `Location` header.
756
- * Defaults to "302 Found".
966
+ * A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
967
+ * that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
968
+ * instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
969
+ * for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
970
+ * header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
971
+ *
972
+ * @example
973
+ * import { replace } from "react-router";
974
+ *
975
+ * export async function loader() {
976
+ * return replace("/new-location");
977
+ * }
757
978
  *
979
+ * @public
758
980
  * @category Utils
981
+ * @mode framework
982
+ * @mode data
983
+ * @param url The URL to redirect to.
984
+ * @param init The status code or a `ResponseInit` object to be included in the
985
+ * response.
986
+ * @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
987
+ * object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
988
+ * header.
759
989
  */
760
990
  declare const replace: RedirectFunction;
761
991
  type ErrorResponse = {
@@ -763,14 +993,6 @@ type ErrorResponse = {
763
993
  statusText: string;
764
994
  data: any;
765
995
  };
766
- /**
767
- * @private
768
- * Utility class we use to hold auto-unwrapped 4xx/5xx Response bodies
769
- *
770
- * We don't export the class for public use since it's an implementation
771
- * detail, but we export the interface above so folks can build their own
772
- * abstractions around instances via isRouteErrorResponse()
773
- */
774
996
  declare class ErrorResponseImpl implements ErrorResponse {
775
997
  status: number;
776
998
  statusText: string;
@@ -780,10 +1002,35 @@ declare class ErrorResponseImpl implements ErrorResponse {
780
1002
  constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
781
1003
  }
782
1004
  /**
783
- * Check if the given error is an ErrorResponse generated from a 4xx/5xx
784
- * Response thrown from an action/loader
1005
+ * Check if the given error is an {@link ErrorResponse} generated from a 4xx/5xx
1006
+ * [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
1007
+ * thrown from an [`action`](../../start/framework/route-module#action)/[`loader`](../../start/framework/route-module#loader)
1008
+ *
1009
+ * @example
1010
+ * import { isRouteErrorResponse } from "react-router";
1011
+ *
1012
+ * export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
1013
+ * if (isRouteErrorResponse(error)) {
1014
+ * return (
1015
+ * <>
1016
+ * <p>Error: `${error.status}: ${error.statusText}`</p>
1017
+ * <p>{error.data}</p>
1018
+ * </>
1019
+ * );
1020
+ * }
1021
+ *
1022
+ * return (
1023
+ * <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
1024
+ * );
1025
+ * }
785
1026
  *
1027
+ * @public
786
1028
  * @category Utils
1029
+ * @mode framework
1030
+ * @mode data
1031
+ * @param error The error to check.
1032
+ * @returns `true` if the error is an {@link ErrorResponse}, `false` otherwise.
1033
+ *
787
1034
  */
788
1035
  declare function isRouteErrorResponse(error: any): error is ErrorResponse;
789
1036
 
@@ -1061,7 +1308,7 @@ interface RouterInit {
1061
1308
  routes: AgnosticRouteObject[];
1062
1309
  history: History;
1063
1310
  basename?: string;
1064
- unstable_getContext?: () => MaybePromise<unstable_InitialContext>;
1311
+ unstable_getContext?: () => MaybePromise<unstable_RouterContextProvider>;
1065
1312
  mapRouteProperties?: MapRoutePropertiesFunction;
1066
1313
  future?: Partial<FutureConfig>;
1067
1314
  hydrationRouteProperties?: string[];
@@ -1096,14 +1343,13 @@ interface StaticHandler {
1096
1343
  skipLoaderErrorBubbling?: boolean;
1097
1344
  skipRevalidation?: boolean;
1098
1345
  dataStrategy?: DataStrategyFunction<unknown>;
1099
- unstable_respond?: (staticContext: StaticHandlerContext) => MaybePromise<Response>;
1100
- unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
1346
+ unstable_generateMiddlewareResponse?: (query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
1101
1347
  }): Promise<StaticHandlerContext | Response>;
1102
1348
  queryRoute(request: Request, opts?: {
1103
1349
  routeId?: string;
1104
1350
  requestContext?: unknown;
1105
1351
  dataStrategy?: DataStrategyFunction<unknown>;
1106
- unstable_respond?: (res: Response) => MaybePromise<Response>;
1352
+ unstable_generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
1107
1353
  }): Promise<any>;
1108
1354
  }
1109
1355
  type ViewTransitionOpts = {
@@ -1454,463 +1700,4 @@ interface RouteContextObject {
1454
1700
  }
1455
1701
  declare const RouteContext: React.Context<RouteContextObject>;
1456
1702
 
1457
- /**
1458
- * An object of unknown type for route loaders and actions provided by the
1459
- * server's `getLoadContext()` function. This is defined as an empty interface
1460
- * specifically so apps can leverage declaration merging to augment this type
1461
- * globally: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
1462
- */
1463
- interface AppLoadContext {
1464
- [key: string]: unknown;
1465
- }
1466
-
1467
- type Primitive = null | undefined | string | number | boolean | symbol | bigint;
1468
- type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1469
- interface HtmlLinkProps {
1470
- /**
1471
- * Address of the hyperlink
1472
- */
1473
- href?: string;
1474
- /**
1475
- * How the element handles crossorigin requests
1476
- */
1477
- crossOrigin?: "anonymous" | "use-credentials";
1478
- /**
1479
- * Relationship between the document containing the hyperlink and the destination resource
1480
- */
1481
- rel: LiteralUnion<"alternate" | "dns-prefetch" | "icon" | "manifest" | "modulepreload" | "next" | "pingback" | "preconnect" | "prefetch" | "preload" | "prerender" | "search" | "stylesheet", string>;
1482
- /**
1483
- * Applicable media: "screen", "print", "(max-width: 764px)"
1484
- */
1485
- media?: string;
1486
- /**
1487
- * Integrity metadata used in Subresource Integrity checks
1488
- */
1489
- integrity?: string;
1490
- /**
1491
- * Language of the linked resource
1492
- */
1493
- hrefLang?: string;
1494
- /**
1495
- * Hint for the type of the referenced resource
1496
- */
1497
- type?: string;
1498
- /**
1499
- * Referrer policy for fetches initiated by the element
1500
- */
1501
- referrerPolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "same-origin" | "origin" | "strict-origin" | "origin-when-cross-origin" | "strict-origin-when-cross-origin" | "unsafe-url";
1502
- /**
1503
- * Sizes of the icons (for rel="icon")
1504
- */
1505
- sizes?: string;
1506
- /**
1507
- * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1508
- */
1509
- as?: LiteralUnion<"audio" | "audioworklet" | "document" | "embed" | "fetch" | "font" | "frame" | "iframe" | "image" | "manifest" | "object" | "paintworklet" | "report" | "script" | "serviceworker" | "sharedworker" | "style" | "track" | "video" | "worker" | "xslt", string>;
1510
- /**
1511
- * Color to use when customizing a site's icon (for rel="mask-icon")
1512
- */
1513
- color?: string;
1514
- /**
1515
- * Whether the link is disabled
1516
- */
1517
- disabled?: boolean;
1518
- /**
1519
- * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
1520
- */
1521
- title?: string;
1522
- /**
1523
- * Images to use in different situations, e.g., high-resolution displays,
1524
- * small monitors, etc. (for rel="preload")
1525
- */
1526
- imageSrcSet?: string;
1527
- /**
1528
- * Image sizes for different page layouts (for rel="preload")
1529
- */
1530
- imageSizes?: string;
1531
- }
1532
- interface HtmlLinkPreloadImage extends HtmlLinkProps {
1533
- /**
1534
- * Relationship between the document containing the hyperlink and the destination resource
1535
- */
1536
- rel: "preload";
1537
- /**
1538
- * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
1539
- */
1540
- as: "image";
1541
- /**
1542
- * Address of the hyperlink
1543
- */
1544
- href?: string;
1545
- /**
1546
- * Images to use in different situations, e.g., high-resolution displays,
1547
- * small monitors, etc. (for rel="preload")
1548
- */
1549
- imageSrcSet: string;
1550
- /**
1551
- * Image sizes for different page layouts (for rel="preload")
1552
- */
1553
- imageSizes?: string;
1554
- }
1555
- /**
1556
- * Represents a `<link>` element.
1557
- *
1558
- * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
1559
- */
1560
- type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "imageSizes">) | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, "href"> & {
1561
- imageSizes?: never;
1562
- });
1563
- interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
1564
- /**
1565
- * The absolute path of the page to prefetch.
1566
- */
1567
- page: string;
1568
- }
1569
- type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;
1570
-
1571
- interface RouteModules {
1572
- [routeId: string]: RouteModule$1 | undefined;
1573
- }
1574
- /**
1575
- * The shape of a route module shipped to the client
1576
- */
1577
- interface RouteModule$1 {
1578
- clientAction?: ClientActionFunction;
1579
- clientLoader?: ClientLoaderFunction;
1580
- unstable_clientMiddleware?: unstable_MiddlewareFunction<undefined>[];
1581
- ErrorBoundary?: ErrorBoundaryComponent;
1582
- HydrateFallback?: HydrateFallbackComponent;
1583
- Layout?: LayoutComponent;
1584
- default: RouteComponent;
1585
- handle?: RouteHandle;
1586
- links?: LinksFunction;
1587
- meta?: MetaFunction;
1588
- shouldRevalidate?: ShouldRevalidateFunction;
1589
- }
1590
- /**
1591
- * The shape of a route module on the server
1592
- */
1593
- interface ServerRouteModule extends RouteModule$1 {
1594
- action?: ActionFunction;
1595
- headers?: HeadersFunction | {
1596
- [name: string]: string;
1597
- };
1598
- loader?: LoaderFunction;
1599
- unstable_middleware?: unstable_MiddlewareFunction<Response>[];
1600
- }
1601
- /**
1602
- * A function that handles data mutations for a route on the client
1603
- */
1604
- type ClientActionFunction = (args: ClientActionFunctionArgs) => ReturnType<ActionFunction>;
1605
- /**
1606
- * Arguments passed to a route `clientAction` function
1607
- */
1608
- type ClientActionFunctionArgs = ActionFunctionArgs & {
1609
- serverAction: <T = unknown>() => Promise<SerializeFrom<T>>;
1610
- };
1611
- /**
1612
- * A function that loads data for a route on the client
1613
- */
1614
- type ClientLoaderFunction = ((args: ClientLoaderFunctionArgs) => ReturnType<LoaderFunction>) & {
1615
- hydrate?: boolean;
1616
- };
1617
- /**
1618
- * Arguments passed to a route `clientLoader` function
1619
- */
1620
- type ClientLoaderFunctionArgs = LoaderFunctionArgs & {
1621
- serverLoader: <T = unknown>() => Promise<SerializeFrom<T>>;
1622
- };
1623
- /**
1624
- * ErrorBoundary to display for this route
1625
- */
1626
- type ErrorBoundaryComponent = ComponentType;
1627
- type HeadersArgs = {
1628
- loaderHeaders: Headers;
1629
- parentHeaders: Headers;
1630
- actionHeaders: Headers;
1631
- errorHeaders: Headers | undefined;
1632
- };
1633
- /**
1634
- * A function that returns HTTP headers to be used for a route. These headers
1635
- * will be merged with (and take precedence over) headers from parent routes.
1636
- */
1637
- interface HeadersFunction {
1638
- (args: HeadersArgs): Headers | HeadersInit;
1639
- }
1640
- /**
1641
- * `<Route HydrateFallback>` component to render on initial loads
1642
- * when client loaders are present
1643
- */
1644
- type HydrateFallbackComponent = ComponentType;
1645
- /**
1646
- * Optional, root-only `<Route Layout>` component to wrap the root content in.
1647
- * Useful for defining the <html>/<head>/<body> document shell shared by the
1648
- * Component, HydrateFallback, and ErrorBoundary
1649
- */
1650
- type LayoutComponent = ComponentType<{
1651
- children: ReactElement<unknown, ErrorBoundaryComponent | HydrateFallbackComponent | RouteComponent>;
1652
- }>;
1653
- /**
1654
- * A function that defines `<link>` tags to be inserted into the `<head>` of
1655
- * the document on route transitions.
1656
- *
1657
- * @see https://remix.run/route/meta
1658
- */
1659
- interface LinksFunction {
1660
- (): LinkDescriptor[];
1661
- }
1662
- interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
1663
- id: RouteId;
1664
- pathname: DataRouteMatch["pathname"];
1665
- data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
1666
- handle?: RouteHandle;
1667
- params: DataRouteMatch["params"];
1668
- meta: MetaDescriptor[];
1669
- error?: unknown;
1670
- }
1671
- type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> = Array<{
1672
- [K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
1673
- }[keyof MatchLoaders]>;
1674
- interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1675
- data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
1676
- params: Params;
1677
- location: Location;
1678
- matches: MetaMatches<MatchLoaders>;
1679
- error?: unknown;
1680
- }
1681
- /**
1682
- * A function that returns an array of data objects to use for rendering
1683
- * metadata HTML tags in a route. These tags are not rendered on descendant
1684
- * routes in the route hierarchy. In other words, they will only be rendered on
1685
- * the route in which they are exported.
1686
- *
1687
- * @param Loader - The type of the current route's loader function
1688
- * @param MatchLoaders - Mapping from a parent route's filepath to its loader
1689
- * function type
1690
- *
1691
- * Note that parent route filepaths are relative to the `app/` directory.
1692
- *
1693
- * For example, if this meta function is for `/sales/customers/$customerId`:
1694
- *
1695
- * ```ts
1696
- * // app/root.tsx
1697
- * const loader = () => ({ hello: "world" })
1698
- * export type Loader = typeof loader
1699
- *
1700
- * // app/routes/sales.tsx
1701
- * const loader = () => ({ salesCount: 1074 })
1702
- * export type Loader = typeof loader
1703
- *
1704
- * // app/routes/sales/customers.tsx
1705
- * const loader = () => ({ customerCount: 74 })
1706
- * export type Loader = typeof loader
1707
- *
1708
- * // app/routes/sales/customers/$customersId.tsx
1709
- * import type { Loader as RootLoader } from "../../../root"
1710
- * import type { Loader as SalesLoader } from "../../sales"
1711
- * import type { Loader as CustomersLoader } from "../../sales/customers"
1712
- *
1713
- * const loader = () => ({ name: "Customer name" })
1714
- *
1715
- * const meta: MetaFunction<typeof loader, {
1716
- * "root": RootLoader,
1717
- * "routes/sales": SalesLoader,
1718
- * "routes/sales/customers": CustomersLoader,
1719
- * }> = ({ data, matches }) => {
1720
- * const { name } = data
1721
- * // ^? string
1722
- * const { customerCount } = matches.find((match) => match.id === "routes/sales/customers").data
1723
- * // ^? number
1724
- * const { salesCount } = matches.find((match) => match.id === "routes/sales").data
1725
- * // ^? number
1726
- * const { hello } = matches.find((match) => match.id === "root").data
1727
- * // ^? "world"
1728
- * }
1729
- * ```
1730
- */
1731
- interface MetaFunction<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
1732
- (args: MetaArgs<Loader, MatchLoaders>): MetaDescriptor[] | undefined;
1733
- }
1734
- type MetaDescriptor = {
1735
- charSet: "utf-8";
1736
- } | {
1737
- title: string;
1738
- } | {
1739
- name: string;
1740
- content: string;
1741
- } | {
1742
- property: string;
1743
- content: string;
1744
- } | {
1745
- httpEquiv: string;
1746
- content: string;
1747
- } | {
1748
- "script:ld+json": LdJsonObject;
1749
- } | {
1750
- tagName: "meta" | "link";
1751
- [name: string]: string;
1752
- } | {
1753
- [name: string]: unknown;
1754
- };
1755
- type LdJsonObject = {
1756
- [Key in string]: LdJsonValue;
1757
- } & {
1758
- [Key in string]?: LdJsonValue | undefined;
1759
- };
1760
- type LdJsonArray = LdJsonValue[] | readonly LdJsonValue[];
1761
- type LdJsonPrimitive = string | number | boolean | null;
1762
- type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
1763
- /**
1764
- * A React component that is rendered for a route.
1765
- */
1766
- type RouteComponent = ComponentType<{}>;
1767
- /**
1768
- * An arbitrary object that is associated with a route.
1769
- *
1770
- * @see https://remix.run/route/handle
1771
- */
1772
- type RouteHandle = unknown;
1773
-
1774
- type Serializable = undefined | null | boolean | string | symbol | number | Array<Serializable> | {
1775
- [key: PropertyKey]: Serializable;
1776
- } | bigint | Date | URL | RegExp | Error | Map<Serializable, Serializable> | Set<Serializable> | Promise<Serializable>;
1777
-
1778
- type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
1779
- type IsAny<T> = 0 extends 1 & T ? true : false;
1780
- type Func = (...args: any[]) => unknown;
1781
- type Pretty<T> = {
1782
- [K in keyof T]: T[K];
1783
- } & {};
1784
- type Normalize<T> = _Normalize<UnionKeys<T>, T>;
1785
- type _Normalize<Key extends keyof any, T> = T extends infer U ? Pretty<{
1786
- [K in Key as K extends keyof U ? undefined extends U[K] ? never : K : never]: K extends keyof U ? U[K] : never;
1787
- } & {
1788
- [K in Key as K extends keyof U ? undefined extends U[K] ? K : never : never]?: K extends keyof U ? U[K] : never;
1789
- } & {
1790
- [K in Key as K extends keyof U ? never : K]?: undefined;
1791
- }> : never;
1792
- type UnionKeys<T> = T extends any ? keyof T : never;
1793
-
1794
- type RouteModule = {
1795
- meta?: Func;
1796
- links?: Func;
1797
- headers?: Func;
1798
- loader?: Func;
1799
- clientLoader?: Func;
1800
- action?: Func;
1801
- clientAction?: Func;
1802
- HydrateFallback?: Func;
1803
- default?: Func;
1804
- ErrorBoundary?: Func;
1805
- [key: string]: unknown;
1806
- };
1807
-
1808
- /**
1809
- * A brand that can be applied to a type to indicate that it will serialize
1810
- * to a specific type when transported to the client from a loader.
1811
- * Only use this if you have additional serialization/deserialization logic
1812
- * in your application.
1813
- */
1814
- type unstable_SerializesTo<T> = {
1815
- unstable__ReactRouter_SerializesTo: [T];
1816
- };
1817
-
1818
- 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> ? {
1819
- [K in keyof T]: Serialize<T[K]>;
1820
- } : undefined;
1821
- type VoidToUndefined<T> = Equal<T, void> extends true ? undefined : T;
1822
- type DataFrom<T> = IsAny<T> extends true ? undefined : T extends Func ? VoidToUndefined<Awaited<ReturnType<T>>> : undefined;
1823
- type ClientData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? U : T;
1824
- type ServerData<T> = T extends Response ? never : T extends DataWithResponseInit<infer U> ? Serialize<U> : Serialize<T>;
1825
- type ServerDataFrom<T> = ServerData<DataFrom<T>>;
1826
- type ClientDataFrom<T> = ClientData<DataFrom<T>>;
1827
- type ClientDataFunctionArgs<Params> = {
1828
- /**
1829
- * 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.
1830
- *
1831
- * @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.
1832
- **/
1833
- request: Request;
1834
- /**
1835
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
1836
- * @example
1837
- * // app/routes.ts
1838
- * route("teams/:teamId", "./team.tsx"),
1839
- *
1840
- * // app/team.tsx
1841
- * export function clientLoader({
1842
- * params,
1843
- * }: Route.ClientLoaderArgs) {
1844
- * params.teamId;
1845
- * // ^ string
1846
- * }
1847
- **/
1848
- params: Params;
1849
- /**
1850
- * When `future.unstable_middleware` is not enabled, this is undefined.
1851
- *
1852
- * When `future.unstable_middleware` is enabled, this is an instance of
1853
- * `unstable_RouterContextProvider` and can be used to access context values
1854
- * from your route middlewares. You may pass in initial context values in your
1855
- * `<HydratedRouter unstable_getContext>` prop
1856
- */
1857
- context: unstable_RouterContextProvider;
1858
- };
1859
- type ServerDataFunctionArgs<Params> = {
1860
- /** 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. */
1861
- request: Request;
1862
- /**
1863
- * {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the current route.
1864
- * @example
1865
- * // app/routes.ts
1866
- * route("teams/:teamId", "./team.tsx"),
1867
- *
1868
- * // app/team.tsx
1869
- * export function loader({
1870
- * params,
1871
- * }: Route.LoaderArgs) {
1872
- * params.teamId;
1873
- * // ^ string
1874
- * }
1875
- **/
1876
- params: Params;
1877
- /**
1878
- * Without `future.unstable_middleware` enabled, this is the context passed in
1879
- * to your server adapter's `getLoadContext` function. It's a way to bridge the
1880
- * gap between the adapter's request/response API with your React Router app.
1881
- * It is only applicable if you are using a custom server adapter.
1882
- *
1883
- * With `future.unstable_middleware` enabled, this is an instance of
1884
- * `unstable_RouterContextProvider` and can be used for type-safe access to
1885
- * context value set in your route middlewares. If you are using a custom
1886
- * server adapter, you may provide an initial set of context values from your
1887
- * `getLoadContext` function.
1888
- */
1889
- context: MiddlewareEnabled extends true ? unstable_RouterContextProvider : AppLoadContext;
1890
- };
1891
- type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
1892
- ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
1893
- ] ? ClientDataFrom<T> : ServerDataFrom<T> : T;
1894
- type IsDefined<T> = Equal<T, undefined> extends true ? false : true;
1895
- type IsHydrate<ClientLoader> = ClientLoader extends {
1896
- hydrate: true;
1897
- } ? true : ClientLoader extends {
1898
- hydrate: false;
1899
- } ? false : false;
1900
- type GetLoaderData<T extends RouteModule> = _DataLoaderData<ServerDataFrom<T["loader"]>, ClientDataFrom<T["clientLoader"]>, IsHydrate<T["clientLoader"]>, T extends {
1901
- HydrateFallback: Func;
1902
- } ? true : false>;
1903
- type _DataLoaderData<ServerLoaderData, ClientLoaderData, ClientLoaderHydrate extends boolean, HasHydrateFallback> = [
1904
- HasHydrateFallback,
1905
- ClientLoaderHydrate
1906
- ] extends [true, true] ? IsDefined<ClientLoaderData> extends true ? ClientLoaderData : undefined : [
1907
- IsDefined<ClientLoaderData>,
1908
- IsDefined<ServerLoaderData>
1909
- ] extends [true, true] ? ServerLoaderData | ClientLoaderData : IsDefined<ClientLoaderData> extends true ? ClientLoaderData : IsDefined<ServerLoaderData> extends true ? ServerLoaderData : undefined;
1910
- type GetActionData<T extends RouteModule> = _DataActionData<ServerDataFrom<T["action"]>, ClientDataFrom<T["clientAction"]>>;
1911
- type _DataActionData<ServerActionData, ClientActionData> = Awaited<[
1912
- IsDefined<ServerActionData>,
1913
- IsDefined<ClientActionData>
1914
- ] extends [true, true] ? ServerActionData | ClientActionData : IsDefined<ClientActionData> extends true ? ClientActionData : IsDefined<ServerActionData> extends true ? ServerActionData : undefined>;
1915
-
1916
- export { type RouterState as $, Action as A, type BlockerFunction as B, type ClientActionFunction as C, type DataStrategyFunction as D, type Blocker as E, type FutureConfig as F, type GetLoaderData as G, type HydrationState as H, type InitialEntry as I, type SerializeFrom as J, type ParamParseKey as K, type LazyRouteFunction as L, type MetaFunction as M, type NonIndexRouteObject as N, type Path as O, type PatchRoutesOnNavigationFunction as P, type PathPattern as Q, type Router as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type PathMatch as V, type Navigation as W, type AppLoadContext as X, type MiddlewareEnabled as Y, type unstable_InitialContext as Z, type Equal as _, type RelativeRoutingType as a, type ServerRouteModule as a$, type DataRouteObject as a0, type StaticHandler as a1, type GetScrollPositionFunction as a2, type GetScrollRestorationKeyFunction as a3, type StaticHandlerContext as a4, type Fetcher as a5, type NavigationStates as a6, type RouterSubscriber as a7, type RouterNavigateOptions as a8, type RouterFetchOptions as a9, matchRoutes as aA, redirect as aB, redirectDocument as aC, replace as aD, resolvePath as aE, type DataRouteMatch as aF, type PatchRoutesOnNavigationFunctionArgs as aG, type ClientActionFunctionArgs as aH, type ClientLoaderFunctionArgs as aI, type HeadersArgs as aJ, type MetaArgs as aK, type PageLinkDescriptor as aL, type HtmlLinkDescriptor as aM, type Future as aN, type unstable_SerializesTo as aO, createBrowserHistory as aP, invariant as aQ, createRouter as aR, ErrorResponseImpl as aS, DataRouterContext as aT, DataRouterStateContext as aU, FetchersContext as aV, LocationContext as aW, NavigationContext as aX, RouteContext as aY, ViewTransitionContext as aZ, type RouteManifest as a_, type RevalidationState as aa, type ActionFunctionArgs as ab, type DataStrategyFunctionArgs as ac, type DataStrategyMatch as ad, type DataStrategyResult as ae, DataWithResponseInit as af, type ErrorResponse as ag, type FormEncType as ah, type FormMethod as ai, type HTMLFormMethod as aj, type LoaderFunctionArgs as ak, type unstable_MiddlewareFunction as al, type PathParam as am, type RedirectFunction as an, type unstable_RouterContext as ao, type ShouldRevalidateFunctionArgs as ap, unstable_createContext as aq, createPath as ar, parsePath as as, IDLE_NAVIGATION as at, IDLE_FETCHER as au, IDLE_BLOCKER as av, data as aw, generatePath as ax, isRouteErrorResponse as ay, matchPath as az, type IndexRouteObject as b, type History as b0, type CreateStaticHandlerOptions as b1, type Location as c, type Navigator as d, type RouterInit as e, type RouteObject as f, type RouteMatch as g, type Params as h, type ActionFunction as i, type ClientLoaderFunction as j, type HeadersFunction as k, type LinksFunction as l, type LoaderFunction as m, type RouteModule as n, type LinkDescriptor as o, type Pretty as p, type MetaDescriptor as q, type ServerDataFunctionArgs as r, type unstable_MiddlewareNextFunction as s, type ClientDataFunctionArgs as t, unstable_RouterContextProvider as u, type ServerDataFrom as v, type Normalize as w, type GetActionData as x, type RouteModules as y, type NavigateOptions as z };
1703
+ export { type ErrorResponse as $, Action as A, type BlockerFunction as B, type StaticHandler as C, type DataStrategyFunction as D, type GetScrollRestorationKeyFunction as E, type FutureConfig as F, type GetScrollPositionFunction as G, type HydrationState as H, type InitialEntry as I, type StaticHandlerContext as J, type Fetcher as K, type LazyRouteFunction as L, type MiddlewareEnabled as M, type NonIndexRouteObject as N, type NavigationStates as O, type PatchRoutesOnNavigationFunction as P, type RouterSubscriber as Q, type Router as R, type ShouldRevalidateFunction as S, type To as T, type UIMatch as U, type RouterNavigateOptions as V, type RouterFetchOptions as W, type RevalidationState as X, type DataStrategyFunctionArgs as Y, type DataStrategyMatch as Z, type DataStrategyResult as _, type RelativeRoutingType as a, type FormEncType as a0, type FormMethod as a1, type HTMLFormMethod as a2, type PathParam as a3, type RedirectFunction as a4, type unstable_RouterContext as a5, type ShouldRevalidateFunctionArgs as a6, unstable_createContext as a7, createPath as a8, parsePath as a9, type History as aA, type CreateStaticHandlerOptions as aB, IDLE_NAVIGATION as aa, IDLE_FETCHER as ab, IDLE_BLOCKER as ac, data as ad, generatePath as ae, isRouteErrorResponse as af, matchPath as ag, matchRoutes as ah, redirect as ai, redirectDocument as aj, replace as ak, resolvePath as al, type PatchRoutesOnNavigationFunctionArgs as am, type Future as an, createBrowserHistory as ao, invariant as ap, createRouter as aq, ErrorResponseImpl as ar, DataRouterContext as as, DataRouterStateContext as at, FetchersContext as au, LocationContext as av, NavigationContext as aw, RouteContext as ax, ViewTransitionContext as ay, type RouteManifest as az, type IndexRouteObject as b, type Location as c, type Navigator as d, type RouterInit as e, type RouteObject as f, type RouteMatch as g, type Params as h, type ActionFunctionArgs as i, type LoaderFunctionArgs as j, type ActionFunction as k, type LoaderFunction as l, type DataRouteMatch as m, type unstable_MiddlewareFunction as n, unstable_RouterContextProvider as o, DataWithResponseInit as p, type NavigateOptions as q, type Blocker as r, type ParamParseKey as s, type Path as t, type unstable_MiddlewareNextFunction as u, type PathPattern as v, type PathMatch as w, type Navigation as x, type RouterState as y, type DataRouteObject as z };