react-router 7.7.1 → 7.8.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -5
- package/dist/development/browser-z32v5KVN.d.mts +46 -0
- package/dist/{production/chunk-K3SBCRK4.mjs → development/chunk-HSC5IU24.mjs} +177 -134
- package/dist/development/{chunk-K7YFBME3.js → chunk-IW6UADHO.js} +250 -187
- package/dist/development/{chunk-C37GKA54.mjs → chunk-SC4OUYO4.mjs} +232 -169
- package/dist/development/{chunk-R73PQUJU.js → chunk-Z4NNCWGU.js} +130 -130
- package/dist/development/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
- package/dist/{production/route-data-CqEmXQub.d.mts → development/context-DZWGFcKX.d.mts} +312 -524
- package/dist/development/dom-export.d.mts +16 -12
- package/dist/development/dom-export.d.ts +13 -8
- package/dist/development/dom-export.js +3 -3
- package/dist/development/dom-export.mjs +3 -3
- package/dist/{production/index-react-server-client-KLg-U4nr.d.mts → development/index-react-server-client-BUK-oRcG.d.mts} +327 -200
- package/dist/development/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
- package/dist/development/index-react-server-client.d.mts +4 -3
- package/dist/development/index-react-server-client.d.ts +2 -2
- package/dist/development/index-react-server-client.js +4 -4
- package/dist/development/index-react-server-client.mjs +2 -2
- package/dist/development/index-react-server.d.mts +291 -70
- package/dist/development/index-react-server.d.ts +291 -70
- package/dist/development/index-react-server.js +174 -180
- package/dist/development/index-react-server.mjs +174 -180
- package/dist/development/index.d.mts +294 -86
- package/dist/development/index.d.ts +136 -105
- package/dist/development/index.js +258 -215
- package/dist/development/index.mjs +3 -3
- package/dist/development/lib/types/internal.d.mts +13 -2
- package/dist/development/lib/types/internal.d.ts +12 -2
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/route-data-UTmTa8an.d.mts +473 -0
- package/dist/{production/routeModules-BR2FO0ix.d.ts → development/routeModules-D5bppTB2.d.ts} +325 -67
- package/dist/production/browser-z32v5KVN.d.mts +46 -0
- package/dist/production/{chunk-4DGLNKXF.js → chunk-BCLZG6QW.js} +130 -130
- package/dist/{development/chunk-KIUJAIYX.mjs → production/chunk-KQ5567DT.mjs} +177 -134
- package/dist/production/{chunk-IZ57JD2V.mjs → chunk-X2NPJMV2.mjs} +232 -169
- package/dist/production/{chunk-7OQROU2D.js → chunk-YC2ENCM3.js} +250 -187
- package/dist/production/{components-CjQijYga.d.mts → components-uUh0svuC.d.mts} +33 -21
- package/dist/{development/route-data-CqEmXQub.d.mts → production/context-DZWGFcKX.d.mts} +312 -524
- package/dist/production/dom-export.d.mts +16 -12
- package/dist/production/dom-export.d.ts +13 -8
- package/dist/production/dom-export.js +3 -3
- package/dist/production/dom-export.mjs +3 -3
- package/dist/{development/index-react-server-client-KLg-U4nr.d.mts → production/index-react-server-client-BUK-oRcG.d.mts} +327 -200
- package/dist/production/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-DSU6bZil.d.ts} +357 -219
- package/dist/production/index-react-server-client.d.mts +4 -3
- package/dist/production/index-react-server-client.d.ts +2 -2
- package/dist/production/index-react-server-client.js +4 -4
- package/dist/production/index-react-server-client.mjs +2 -2
- package/dist/production/index-react-server.d.mts +291 -70
- package/dist/production/index-react-server.d.ts +291 -70
- package/dist/production/index-react-server.js +174 -180
- package/dist/production/index-react-server.mjs +174 -180
- package/dist/production/index.d.mts +294 -86
- package/dist/production/index.d.ts +136 -105
- package/dist/production/index.js +258 -215
- package/dist/production/index.mjs +3 -3
- package/dist/production/lib/types/internal.d.mts +13 -2
- package/dist/production/lib/types/internal.d.ts +12 -2
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/production/route-data-UTmTa8an.d.mts +473 -0
- package/dist/{development/routeModules-BR2FO0ix.d.ts → production/routeModules-D5bppTB2.d.ts} +325 -67
- package/package.json +1 -1
- package/dist/development/browser-7LYX59NK.d.mts +0 -226
- 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,123 @@ 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
|
|
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
|
+
* <docs-warning>Enable this API with the `future.unstable_middleware` flag.</docs-warning>
|
|
289
|
+
*
|
|
290
|
+
* If a `defaultValue` is provided, it will be returned from `context.get()`
|
|
291
|
+
* when no value has been set for the context. Otherwise, reading this context
|
|
292
|
+
* when no value has been set will throw an error.
|
|
293
|
+
*
|
|
294
|
+
* ```tsx filename=app/context.ts
|
|
295
|
+
* import { unstable_createContext } from "react-router";
|
|
296
|
+
*
|
|
297
|
+
* // Create a context for user data
|
|
298
|
+
* export const userContext =
|
|
299
|
+
* unstable_createContext<User | null>(null);
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* ```tsx filename=app/middleware/auth.ts
|
|
303
|
+
* import { getUserFromSession } from "~/auth.server";
|
|
304
|
+
* import { userContext } from "~/context";
|
|
279
305
|
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
306
|
+
* export const authMiddleware = async ({
|
|
307
|
+
* context,
|
|
308
|
+
* request,
|
|
309
|
+
* }) => {
|
|
310
|
+
* const user = await getUserFromSession(request);
|
|
311
|
+
* context.set(userContext, user);
|
|
312
|
+
* };
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* ```tsx filename=app/routes/profile.tsx
|
|
316
|
+
* import { userContext } from "~/context";
|
|
317
|
+
*
|
|
318
|
+
* export async function loader({
|
|
319
|
+
* context,
|
|
320
|
+
* }: Route.LoaderArgs) {
|
|
321
|
+
* const user = context.get(userContext);
|
|
322
|
+
*
|
|
323
|
+
* if (!user) {
|
|
324
|
+
* throw new Response("Unauthorized", { status: 401 });
|
|
325
|
+
* }
|
|
326
|
+
*
|
|
327
|
+
* return { user };
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
283
330
|
*
|
|
284
|
-
* @
|
|
285
|
-
* @
|
|
331
|
+
* @public
|
|
332
|
+
* @category Utils
|
|
333
|
+
* @mode framework
|
|
334
|
+
* @mode data
|
|
335
|
+
* @param defaultValue An optional default value for the context. This value
|
|
336
|
+
* will be returned if no value has been set for this context.
|
|
337
|
+
* @returns A {@link unstable_RouterContext} object that can be used with
|
|
338
|
+
* `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
|
|
339
|
+
* [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
|
|
286
340
|
*/
|
|
287
341
|
declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
|
|
288
342
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
*
|
|
343
|
+
* Provides methods for writing/reading values in application context in a
|
|
344
|
+
* type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* import {
|
|
348
|
+
* unstable_createContext,
|
|
349
|
+
* unstable_RouterContextProvider
|
|
350
|
+
* } from "react-router";
|
|
351
|
+
*
|
|
352
|
+
* const userContext = unstable_createContext<User | null>(null);
|
|
353
|
+
* const contextProvider = new unstable_RouterContextProvider();
|
|
354
|
+
* contextProvider.set(userContext, getUser());
|
|
355
|
+
* const user = contextProvider.get(userContext);
|
|
356
|
+
* // ^ User
|
|
357
|
+
*
|
|
358
|
+
* @public
|
|
359
|
+
* @category Utils
|
|
360
|
+
* @mode framework
|
|
361
|
+
* @mode data
|
|
295
362
|
*/
|
|
296
363
|
declare class unstable_RouterContextProvider {
|
|
297
364
|
#private;
|
|
298
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Create a new `unstable_RouterContextProvider` instance
|
|
367
|
+
* @param init An optional initial context map to populate the provider with
|
|
368
|
+
*/
|
|
369
|
+
constructor(init?: Map<unstable_RouterContext, unknown>);
|
|
370
|
+
/**
|
|
371
|
+
* Access a value from the context. If no value has been set for the context,
|
|
372
|
+
* it will return the context's `defaultValue` if provided, or throw an error
|
|
373
|
+
* if no `defaultValue` was set.
|
|
374
|
+
* @param context The context to get the value for
|
|
375
|
+
* @returns The value for the context, or the context's `defaultValue` if no
|
|
376
|
+
* value was set
|
|
377
|
+
*/
|
|
299
378
|
get<T>(context: unstable_RouterContext<T>): T;
|
|
379
|
+
/**
|
|
380
|
+
* Set a value for the context. If the context already has a value set, this
|
|
381
|
+
* will overwrite it.
|
|
382
|
+
*
|
|
383
|
+
* @param context The context to set the value for
|
|
384
|
+
* @param value The value to set for the context
|
|
385
|
+
* @returns {void}
|
|
386
|
+
*/
|
|
300
387
|
set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
|
|
301
388
|
}
|
|
302
|
-
type DefaultContext = MiddlewareEnabled extends true ? unstable_RouterContextProvider : any;
|
|
389
|
+
type DefaultContext = MiddlewareEnabled extends true ? Readonly<unstable_RouterContextProvider> : any;
|
|
303
390
|
/**
|
|
304
391
|
* @private
|
|
305
392
|
* Arguments passed to route loader/action functions. Same for now but we keep
|
|
@@ -321,7 +408,7 @@ interface DataFunctionArgs<Context> {
|
|
|
321
408
|
* params.teamId;
|
|
322
409
|
* // ^ string
|
|
323
410
|
* }
|
|
324
|
-
|
|
411
|
+
*/
|
|
325
412
|
params: Params;
|
|
326
413
|
/**
|
|
327
414
|
* This is the context passed in to your server adapter's getLoadContext() function.
|
|
@@ -343,7 +430,7 @@ interface unstable_MiddlewareNextFunction<Result = unknown> {
|
|
|
343
430
|
* a `next` function as the second parameter which will call downstream handlers
|
|
344
431
|
* and then complete middlewares from the bottom-up
|
|
345
432
|
*/
|
|
346
|
-
type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<unstable_RouterContextProvider
|
|
433
|
+
type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<unstable_RouterContextProvider>>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
|
|
347
434
|
/**
|
|
348
435
|
* Arguments passed to loader functions
|
|
349
436
|
*/
|
|
@@ -449,34 +536,39 @@ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRoute
|
|
|
449
536
|
route: Promise<void> | undefined;
|
|
450
537
|
};
|
|
451
538
|
/**
|
|
452
|
-
* A boolean value indicating whether this route handler should be called in
|
|
539
|
+
* A boolean value indicating whether this route handler should be called in
|
|
540
|
+
* this pass.
|
|
453
541
|
*
|
|
454
|
-
* The `matches` array always includes _all_ matched routes even when only
|
|
455
|
-
* route handlers need to be called so that things like middleware can
|
|
542
|
+
* The `matches` array always includes _all_ matched routes even when only
|
|
543
|
+
* _some_ route handlers need to be called so that things like middleware can
|
|
544
|
+
* be implemented.
|
|
456
545
|
*
|
|
457
|
-
* `shouldLoad` is usually only interesting if you are skipping the route
|
|
458
|
-
* entirely and implementing custom handler logic - since it lets you
|
|
459
|
-
* if that custom logic should run for this route or not.
|
|
546
|
+
* `shouldLoad` is usually only interesting if you are skipping the route
|
|
547
|
+
* handler entirely and implementing custom handler logic - since it lets you
|
|
548
|
+
* determine if that custom logic should run for this route or not.
|
|
460
549
|
*
|
|
461
550
|
* For example:
|
|
462
551
|
* - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
|
|
463
552
|
* you'll get an array of three matches (`[parent, child, b]`), but only `b`
|
|
464
553
|
* will have `shouldLoad=true` because the data for `parent` and `child` is
|
|
465
554
|
* already loaded
|
|
466
|
-
* - If you are on `/parent/child/a` and you submit to `a`'s `action
|
|
467
|
-
* `a` will have `shouldLoad=true` for the action execution of
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
555
|
+
* - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
|
|
556
|
+
* then only `a` will have `shouldLoad=true` for the action execution of
|
|
557
|
+
* `dataStrategy`
|
|
558
|
+
* - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
|
|
559
|
+
* `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
|
|
560
|
+
* revalidation, and all matches will have `shouldLoad=true` (assuming no
|
|
561
|
+
* custom `shouldRevalidate` implementations)
|
|
471
562
|
*/
|
|
472
563
|
shouldLoad: boolean;
|
|
473
564
|
unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
|
|
474
565
|
unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
|
|
475
566
|
/**
|
|
476
567
|
* An async function that will resolve any `route.lazy` implementations and
|
|
477
|
-
* execute the route's handler (if necessary), returning a
|
|
568
|
+
* execute the route's handler (if necessary), returning a {@link DataStrategyResult}
|
|
478
569
|
*
|
|
479
|
-
* - Calling `match.resolve` does not mean you're calling the
|
|
570
|
+
* - Calling `match.resolve` does not mean you're calling the
|
|
571
|
+
* [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
|
|
480
572
|
* (the "handler") - `resolve` will only call the `handler` internally if
|
|
481
573
|
* needed _and_ if you don't pass your own `handlerOverride` function parameter
|
|
482
574
|
* - It is safe to call `match.resolve` for all matches, even if they have
|
|
@@ -643,7 +735,28 @@ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticData
|
|
|
643
735
|
/**
|
|
644
736
|
* Matches the given routes to a location and returns the match data.
|
|
645
737
|
*
|
|
738
|
+
* @example
|
|
739
|
+
* import { matchRoutes } from "react-router";
|
|
740
|
+
*
|
|
741
|
+
* let routes = [{
|
|
742
|
+
* path: "/",
|
|
743
|
+
* Component: Root,
|
|
744
|
+
* children: [{
|
|
745
|
+
* path: "dashboard",
|
|
746
|
+
* Component: Dashboard,
|
|
747
|
+
* }]
|
|
748
|
+
* }];
|
|
749
|
+
*
|
|
750
|
+
* matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
|
|
751
|
+
*
|
|
752
|
+
* @public
|
|
646
753
|
* @category Utils
|
|
754
|
+
* @param routes The array of route objects to match against.
|
|
755
|
+
* @param locationArg The location to match against, either a string path or a
|
|
756
|
+
* partial {@link Location} object
|
|
757
|
+
* @param basename Optional base path to strip from the location before matching.
|
|
758
|
+
* Defaults to `/`.
|
|
759
|
+
* @returns An array of matched routes, or `null` if no matches were found.
|
|
647
760
|
*/
|
|
648
761
|
declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
|
|
649
762
|
interface UIMatch<Data = unknown, Handle = unknown> {
|
|
@@ -651,29 +764,53 @@ interface UIMatch<Data = unknown, Handle = unknown> {
|
|
|
651
764
|
pathname: string;
|
|
652
765
|
/**
|
|
653
766
|
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
|
|
654
|
-
|
|
767
|
+
*/
|
|
655
768
|
params: AgnosticRouteMatch["params"];
|
|
656
|
-
/**
|
|
657
|
-
|
|
658
|
-
|
|
769
|
+
/**
|
|
770
|
+
* The return value from the matched route's loader or clientLoader. This might
|
|
771
|
+
* be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
|
|
772
|
+
* an error and we're currently displaying an `ErrorBoundary`.
|
|
773
|
+
*
|
|
774
|
+
* @deprecated Use `UIMatch.loaderData` instead
|
|
775
|
+
*/
|
|
776
|
+
data: Data | undefined;
|
|
777
|
+
/**
|
|
778
|
+
* The return value from the matched route's loader or clientLoader. This might
|
|
779
|
+
* be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
|
|
780
|
+
* an error and we're currently displaying an `ErrorBoundary`.
|
|
781
|
+
*/
|
|
782
|
+
loaderData: Data | undefined;
|
|
783
|
+
/**
|
|
784
|
+
* The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
|
|
785
|
+
* exported from the matched route module
|
|
786
|
+
*/
|
|
659
787
|
handle: Handle;
|
|
660
788
|
}
|
|
661
789
|
/**
|
|
662
790
|
* Returns a path with params interpolated.
|
|
663
791
|
*
|
|
792
|
+
* @example
|
|
793
|
+
* import { generatePath } from "react-router";
|
|
794
|
+
*
|
|
795
|
+
* generatePath("/users/:id", { id: "123" }); // "/users/123"
|
|
796
|
+
*
|
|
797
|
+
* @public
|
|
664
798
|
* @category Utils
|
|
799
|
+
* @param originalPath The original path to generate.
|
|
800
|
+
* @param params The parameters to interpolate into the path.
|
|
801
|
+
* @returns The generated path with parameters interpolated.
|
|
665
802
|
*/
|
|
666
803
|
declare function generatePath<Path extends string>(originalPath: Path, params?: {
|
|
667
804
|
[key in PathParam<Path>]: string | null;
|
|
668
805
|
}): string;
|
|
669
806
|
/**
|
|
670
|
-
*
|
|
807
|
+
* Used to match on some portion of a URL pathname.
|
|
671
808
|
*/
|
|
672
809
|
interface PathPattern<Path extends string = string> {
|
|
673
810
|
/**
|
|
674
811
|
* A string to match against a URL pathname. May contain `:id`-style segments
|
|
675
|
-
* to indicate placeholders for dynamic parameters. May also end with `/*`
|
|
676
|
-
* indicate matching the rest of the URL pathname.
|
|
812
|
+
* to indicate placeholders for dynamic parameters. It May also end with `/*`
|
|
813
|
+
* to indicate matching the rest of the URL pathname.
|
|
677
814
|
*/
|
|
678
815
|
path: Path;
|
|
679
816
|
/**
|
|
@@ -687,7 +824,7 @@ interface PathPattern<Path extends string = string> {
|
|
|
687
824
|
end?: boolean;
|
|
688
825
|
}
|
|
689
826
|
/**
|
|
690
|
-
*
|
|
827
|
+
* Contains info about how a {@link PathPattern} matched on a URL pathname.
|
|
691
828
|
*/
|
|
692
829
|
interface PathMatch<ParamKey extends string = string> {
|
|
693
830
|
/**
|
|
@@ -711,13 +848,26 @@ interface PathMatch<ParamKey extends string = string> {
|
|
|
711
848
|
* Performs pattern matching on a URL pathname and returns information about
|
|
712
849
|
* the match.
|
|
713
850
|
*
|
|
851
|
+
* @public
|
|
714
852
|
* @category Utils
|
|
853
|
+
* @param pattern The pattern to match against the URL pathname. This can be a
|
|
854
|
+
* string or a {@link PathPattern} object. If a string is provided, it will be
|
|
855
|
+
* treated as a pattern with `caseSensitive` set to `false` and `end` set to
|
|
856
|
+
* `true`.
|
|
857
|
+
* @param pathname The URL pathname to match against the pattern.
|
|
858
|
+
* @returns A path match object if the pattern matches the pathname,
|
|
859
|
+
* or `null` if it does not match.
|
|
715
860
|
*/
|
|
716
861
|
declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
|
|
717
862
|
/**
|
|
718
|
-
* Returns a resolved
|
|
863
|
+
* Returns a resolved {@link Path} object relative to the given pathname.
|
|
719
864
|
*
|
|
865
|
+
* @public
|
|
720
866
|
* @category Utils
|
|
867
|
+
* @param to The path to resolve, either a string or a partial {@link Path}
|
|
868
|
+
* object.
|
|
869
|
+
* @param fromPathname The pathname to resolve the path from. Defaults to `/`.
|
|
870
|
+
* @returns A {@link Path} object with the resolved pathname, search, and hash.
|
|
721
871
|
*/
|
|
722
872
|
declare function resolvePath(to: To, fromPathname?: string): Path;
|
|
723
873
|
declare class DataWithResponseInit<D> {
|
|
@@ -727,35 +877,116 @@ declare class DataWithResponseInit<D> {
|
|
|
727
877
|
constructor(data: D, init?: ResponseInit);
|
|
728
878
|
}
|
|
729
879
|
/**
|
|
730
|
-
* Create "responses" that contain `status
|
|
731
|
-
* serialization into an actual `Response`
|
|
880
|
+
* Create "responses" that contain `headers`/`status` without forcing
|
|
881
|
+
* serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* import { data } from "react-router";
|
|
885
|
+
*
|
|
886
|
+
* export async function action({ request }: Route.ActionArgs) {
|
|
887
|
+
* let formData = await request.formData();
|
|
888
|
+
* let item = await createItem(formData);
|
|
889
|
+
* return data(item, {
|
|
890
|
+
* headers: { "X-Custom-Header": "value" }
|
|
891
|
+
* status: 201,
|
|
892
|
+
* });
|
|
893
|
+
* }
|
|
732
894
|
*
|
|
895
|
+
* @public
|
|
733
896
|
* @category Utils
|
|
897
|
+
* @mode framework
|
|
898
|
+
* @mode data
|
|
899
|
+
* @param data The data to be included in the response.
|
|
900
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
901
|
+
* response.
|
|
902
|
+
* @returns A {@link DataWithResponseInit} instance containing the data and
|
|
903
|
+
* response init.
|
|
734
904
|
*/
|
|
735
905
|
declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
|
|
736
906
|
type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
|
|
737
907
|
/**
|
|
738
|
-
* A redirect
|
|
739
|
-
*
|
|
908
|
+
* A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
|
|
909
|
+
* Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
910
|
+
* header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* import { redirect } from "react-router";
|
|
914
|
+
*
|
|
915
|
+
* export async function loader({ request }: Route.LoaderArgs) {
|
|
916
|
+
* if (!isLoggedIn(request))
|
|
917
|
+
* throw redirect("/login");
|
|
918
|
+
* }
|
|
919
|
+
*
|
|
920
|
+
* // ...
|
|
921
|
+
* }
|
|
740
922
|
*
|
|
923
|
+
* @public
|
|
741
924
|
* @category Utils
|
|
925
|
+
* @mode framework
|
|
926
|
+
* @mode data
|
|
927
|
+
* @param url The URL to redirect to.
|
|
928
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
929
|
+
* response.
|
|
930
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
931
|
+
* object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
932
|
+
* header.
|
|
742
933
|
*/
|
|
743
934
|
declare const redirect: RedirectFunction;
|
|
744
935
|
/**
|
|
745
|
-
* A redirect
|
|
746
|
-
*
|
|
747
|
-
*
|
|
936
|
+
* A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
937
|
+
* that will force a document reload to the new location. Sets the status code
|
|
938
|
+
* and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
939
|
+
* header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
|
|
940
|
+
*
|
|
941
|
+
* ```tsx filename=routes/logout.tsx
|
|
942
|
+
* import { redirectDocument } from "react-router";
|
|
748
943
|
*
|
|
944
|
+
* import { destroySession } from "../sessions.server";
|
|
945
|
+
*
|
|
946
|
+
* export async function action({ request }: Route.ActionArgs) {
|
|
947
|
+
* let session = await getSession(request.headers.get("Cookie"));
|
|
948
|
+
* return redirectDocument("/", {
|
|
949
|
+
* headers: { "Set-Cookie": await destroySession(session) }
|
|
950
|
+
* });
|
|
951
|
+
* }
|
|
952
|
+
* ```
|
|
953
|
+
*
|
|
954
|
+
* @public
|
|
749
955
|
* @category Utils
|
|
956
|
+
* @mode framework
|
|
957
|
+
* @mode data
|
|
958
|
+
* @param url The URL to redirect to.
|
|
959
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
960
|
+
* response.
|
|
961
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
962
|
+
* object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
963
|
+
* header.
|
|
750
964
|
*/
|
|
751
965
|
declare const redirectDocument: RedirectFunction;
|
|
752
966
|
/**
|
|
753
|
-
* A redirect
|
|
754
|
-
* `history.
|
|
755
|
-
*
|
|
756
|
-
*
|
|
967
|
+
* A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
968
|
+
* that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
|
|
969
|
+
* instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
|
|
970
|
+
* for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
971
|
+
* header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
|
|
757
972
|
*
|
|
973
|
+
* @example
|
|
974
|
+
* import { replace } from "react-router";
|
|
975
|
+
*
|
|
976
|
+
* export async function loader() {
|
|
977
|
+
* return replace("/new-location");
|
|
978
|
+
* }
|
|
979
|
+
*
|
|
980
|
+
* @public
|
|
758
981
|
* @category Utils
|
|
982
|
+
* @mode framework
|
|
983
|
+
* @mode data
|
|
984
|
+
* @param url The URL to redirect to.
|
|
985
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
986
|
+
* response.
|
|
987
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
988
|
+
* object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
989
|
+
* header.
|
|
759
990
|
*/
|
|
760
991
|
declare const replace: RedirectFunction;
|
|
761
992
|
type ErrorResponse = {
|
|
@@ -763,14 +994,6 @@ type ErrorResponse = {
|
|
|
763
994
|
statusText: string;
|
|
764
995
|
data: any;
|
|
765
996
|
};
|
|
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
997
|
declare class ErrorResponseImpl implements ErrorResponse {
|
|
775
998
|
status: number;
|
|
776
999
|
statusText: string;
|
|
@@ -780,10 +1003,35 @@ declare class ErrorResponseImpl implements ErrorResponse {
|
|
|
780
1003
|
constructor(status: number, statusText: string | undefined, data: any, internal?: boolean);
|
|
781
1004
|
}
|
|
782
1005
|
/**
|
|
783
|
-
* Check if the given error is an ErrorResponse generated from a 4xx/5xx
|
|
784
|
-
* Response
|
|
1006
|
+
* Check if the given error is an {@link ErrorResponse} generated from a 4xx/5xx
|
|
1007
|
+
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
1008
|
+
* thrown from an [`action`](../../start/framework/route-module#action)/[`loader`](../../start/framework/route-module#loader)
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* import { isRouteErrorResponse } from "react-router";
|
|
1012
|
+
*
|
|
1013
|
+
* export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
|
|
1014
|
+
* if (isRouteErrorResponse(error)) {
|
|
1015
|
+
* return (
|
|
1016
|
+
* <>
|
|
1017
|
+
* <p>Error: `${error.status}: ${error.statusText}`</p>
|
|
1018
|
+
* <p>{error.data}</p>
|
|
1019
|
+
* </>
|
|
1020
|
+
* );
|
|
1021
|
+
* }
|
|
785
1022
|
*
|
|
1023
|
+
* return (
|
|
1024
|
+
* <p>Error: {error instanceof Error ? error.message : "Unknown Error"}</p>
|
|
1025
|
+
* );
|
|
1026
|
+
* }
|
|
1027
|
+
*
|
|
1028
|
+
* @public
|
|
786
1029
|
* @category Utils
|
|
1030
|
+
* @mode framework
|
|
1031
|
+
* @mode data
|
|
1032
|
+
* @param error The error to check.
|
|
1033
|
+
* @returns `true` if the error is an {@link ErrorResponse}, `false` otherwise.
|
|
1034
|
+
*
|
|
787
1035
|
*/
|
|
788
1036
|
declare function isRouteErrorResponse(error: any): error is ErrorResponse;
|
|
789
1037
|
|
|
@@ -1061,7 +1309,7 @@ interface RouterInit {
|
|
|
1061
1309
|
routes: AgnosticRouteObject[];
|
|
1062
1310
|
history: History;
|
|
1063
1311
|
basename?: string;
|
|
1064
|
-
unstable_getContext?: () => MaybePromise<
|
|
1312
|
+
unstable_getContext?: () => MaybePromise<unstable_RouterContextProvider>;
|
|
1065
1313
|
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
1066
1314
|
future?: Partial<FutureConfig>;
|
|
1067
1315
|
hydrationRouteProperties?: string[];
|
|
@@ -1096,14 +1344,13 @@ interface StaticHandler {
|
|
|
1096
1344
|
skipLoaderErrorBubbling?: boolean;
|
|
1097
1345
|
skipRevalidation?: boolean;
|
|
1098
1346
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
1099
|
-
|
|
1100
|
-
unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
1347
|
+
unstable_generateMiddlewareResponse?: (query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
1101
1348
|
}): Promise<StaticHandlerContext | Response>;
|
|
1102
1349
|
queryRoute(request: Request, opts?: {
|
|
1103
1350
|
routeId?: string;
|
|
1104
1351
|
requestContext?: unknown;
|
|
1105
1352
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
1106
|
-
|
|
1353
|
+
unstable_generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
|
|
1107
1354
|
}): Promise<any>;
|
|
1108
1355
|
}
|
|
1109
1356
|
type ViewTransitionOpts = {
|
|
@@ -1454,463 +1701,4 @@ interface RouteContextObject {
|
|
|
1454
1701
|
}
|
|
1455
1702
|
declare const RouteContext: React.Context<RouteContextObject>;
|
|
1456
1703
|
|
|
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 };
|
|
1704
|
+
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 };
|