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.
- package/CHANGELOG.md +87 -5
- package/dist/development/browser-z32v5KVN.d.mts +46 -0
- package/dist/development/{chunk-R73PQUJU.js → chunk-4EVDZJGM.js} +130 -130
- package/dist/{production/chunk-K3SBCRK4.mjs → development/chunk-I22FVTOY.mjs} +177 -134
- package/dist/development/{chunk-K7YFBME3.js → chunk-NGF2R4G7.js} +285 -189
- package/dist/development/{chunk-C37GKA54.mjs → chunk-XFFANEXU.mjs} +266 -170
- package/dist/development/{components-CjQijYga.d.mts → components-CuPfnyiZ.d.mts} +33 -21
- package/dist/{production/route-data-CqEmXQub.d.mts → development/context-DohQKLID.d.mts} +312 -525
- 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/development/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-BzBbJLAD.d.ts} +357 -219
- package/dist/{production/index-react-server-client-KLg-U4nr.d.mts → development/index-react-server-client-CuajY2vy.d.mts} +327 -200
- 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 -71
- package/dist/development/index-react-server.d.ts +291 -71
- package/dist/development/index-react-server.js +209 -182
- package/dist/development/index-react-server.mjs +209 -182
- 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-CpB5xtMm.d.mts +473 -0
- package/dist/{production/routeModules-BR2FO0ix.d.ts → development/routeModules-qBivMBjd.d.ts} +325 -68
- package/dist/production/browser-z32v5KVN.d.mts +46 -0
- package/dist/production/{chunk-4DGLNKXF.js → chunk-4PESVXQ2.js} +130 -130
- package/dist/{development/chunk-KIUJAIYX.mjs → production/chunk-JJOMWYJ4.mjs} +177 -134
- package/dist/production/{chunk-IZ57JD2V.mjs → chunk-P2ZJHOXZ.mjs} +266 -170
- package/dist/production/{chunk-7OQROU2D.js → chunk-RLJ23MYZ.js} +285 -189
- package/dist/production/{components-CjQijYga.d.mts → components-CuPfnyiZ.d.mts} +33 -21
- package/dist/{development/route-data-CqEmXQub.d.mts → production/context-DohQKLID.d.mts} +312 -525
- 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/production/{index-react-server-client-Bi_fx8qz.d.ts → index-react-server-client-BzBbJLAD.d.ts} +357 -219
- package/dist/{development/index-react-server-client-KLg-U4nr.d.mts → production/index-react-server-client-CuajY2vy.d.mts} +327 -200
- 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 -71
- package/dist/production/index-react-server.d.ts +291 -71
- package/dist/production/index-react-server.js +209 -182
- package/dist/production/index-react-server.mjs +209 -182
- 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-CpB5xtMm.d.mts +473 -0
- package/dist/{development/routeModules-BR2FO0ix.d.ts → production/routeModules-qBivMBjd.d.ts} +325 -68
- package/package.json +1 -1
- package/dist/development/browser-7LYX59NK.d.mts +0 -226
- package/dist/production/browser-7LYX59NK.d.mts +0 -226
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
export { Await, BrowserRouter, Form, HashRouter, Link, Links, MemoryRouter, Meta, NavLink, Navigate, Outlet, Route, Router, RouterProvider, Routes, ScrollRestoration, StaticRouter, StaticRouterProvider, unstable_HistoryRouter } from 'react-router/internal/react-server-client';
|
|
4
3
|
import { ParseOptions, SerializeOptions } from 'cookie';
|
|
@@ -228,35 +227,122 @@ type Submission = {
|
|
|
228
227
|
json: undefined;
|
|
229
228
|
text: string;
|
|
230
229
|
};
|
|
230
|
+
/**
|
|
231
|
+
* A context instance used as the key for the `get`/`set` methods of a
|
|
232
|
+
* {@link unstable_RouterContextProvider}. Accepts an optional default
|
|
233
|
+
* value to be returned if no value has been set.
|
|
234
|
+
*/
|
|
231
235
|
interface unstable_RouterContext<T = unknown> {
|
|
232
236
|
defaultValue?: T;
|
|
233
237
|
}
|
|
234
238
|
/**
|
|
235
|
-
* Creates a
|
|
239
|
+
* Creates a type-safe {@link unstable_RouterContext} object that can be used to
|
|
240
|
+
* store and retrieve arbitrary values in [`action`](../../start/framework/route-module#action)s,
|
|
241
|
+
* [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
|
|
242
|
+
* Similar to React's [`createContext`](https://react.dev/reference/react/createContext),
|
|
243
|
+
* but specifically designed for React Router's request/response lifecycle.
|
|
244
|
+
*
|
|
245
|
+
* If a `defaultValue` is provided, it will be returned from `context.get()`
|
|
246
|
+
* when no value has been set for the context. Otherwise, reading this context
|
|
247
|
+
* when no value has been set will throw an error.
|
|
248
|
+
*
|
|
249
|
+
* ```tsx filename=app/context.ts
|
|
250
|
+
* import { unstable_createContext } from "react-router";
|
|
251
|
+
*
|
|
252
|
+
* // Create a context for user data
|
|
253
|
+
* export const userContext =
|
|
254
|
+
* unstable_createContext<User | null>(null);
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* ```tsx filename=app/middleware/auth.ts
|
|
258
|
+
* import { getUserFromSession } from "~/auth.server";
|
|
259
|
+
* import { userContext } from "~/context";
|
|
260
|
+
*
|
|
261
|
+
* export const authMiddleware = async ({
|
|
262
|
+
* context,
|
|
263
|
+
* request,
|
|
264
|
+
* }) => {
|
|
265
|
+
* const user = await getUserFromSession(request);
|
|
266
|
+
* context.set(userContext, user);
|
|
267
|
+
* };
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* ```tsx filename=app/routes/profile.tsx
|
|
271
|
+
* import { userContext } from "~/context";
|
|
236
272
|
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
273
|
+
* export async function loader({
|
|
274
|
+
* context,
|
|
275
|
+
* }: Route.LoaderArgs) {
|
|
276
|
+
* const user = context.get(userContext);
|
|
240
277
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
278
|
+
* if (!user) {
|
|
279
|
+
* throw new Response("Unauthorized", { status: 401 });
|
|
280
|
+
* }
|
|
281
|
+
*
|
|
282
|
+
* return { user };
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
*
|
|
286
|
+
* @public
|
|
287
|
+
* @category Utils
|
|
288
|
+
* @mode framework
|
|
289
|
+
* @mode data
|
|
290
|
+
* @param defaultValue An optional default value for the context. This value
|
|
291
|
+
* will be returned if no value has been set for this context.
|
|
292
|
+
* @returns A {@link unstable_RouterContext} object that can be used with
|
|
293
|
+
* `context.get()` and `context.set()` in [`action`](../../start/framework/route-module#action)s,
|
|
294
|
+
* [`loader`](../../start/framework/route-module#loader)s, and [middleware](../../how-to/middleware).
|
|
243
295
|
*/
|
|
244
296
|
declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
|
|
245
297
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
*
|
|
298
|
+
* Provides methods for writing/reading values in application context in a
|
|
299
|
+
* type-safe way. Primarily for usage with [middleware](../../how-to/middleware).
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* import {
|
|
303
|
+
* unstable_createContext,
|
|
304
|
+
* unstable_RouterContextProvider
|
|
305
|
+
* } from "react-router";
|
|
306
|
+
*
|
|
307
|
+
* const userContext = unstable_createContext<User | null>(null);
|
|
308
|
+
* const contextProvider = new unstable_RouterContextProvider();
|
|
309
|
+
* contextProvider.set(userContext, getUser());
|
|
310
|
+
* // ^ Type-safe
|
|
311
|
+
* const user = contextProvider.get(userContext);
|
|
312
|
+
* // ^ User
|
|
313
|
+
*
|
|
314
|
+
* @public
|
|
315
|
+
* @category Utils
|
|
316
|
+
* @mode framework
|
|
317
|
+
* @mode data
|
|
252
318
|
*/
|
|
253
319
|
declare class unstable_RouterContextProvider {
|
|
254
320
|
#private;
|
|
255
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Create a new `unstable_RouterContextProvider` instance
|
|
323
|
+
* @param init An optional initial context map to populate the provider with
|
|
324
|
+
*/
|
|
325
|
+
constructor(init?: Map<unstable_RouterContext, unknown>);
|
|
326
|
+
/**
|
|
327
|
+
* Access a value from the context. If no value has been set for the context,
|
|
328
|
+
* it will return the context's `defaultValue` if provided, or throw an error
|
|
329
|
+
* if no `defaultValue` was set.
|
|
330
|
+
* @param context The context to get the value for
|
|
331
|
+
* @returns The value for the context, or the context's `defaultValue` if no
|
|
332
|
+
* value was set
|
|
333
|
+
*/
|
|
256
334
|
get<T>(context: unstable_RouterContext<T>): T;
|
|
335
|
+
/**
|
|
336
|
+
* Set a value for the context. If the context already has a value set, this
|
|
337
|
+
* will overwrite it.
|
|
338
|
+
*
|
|
339
|
+
* @param context The context to set the value for
|
|
340
|
+
* @param value The value to set for the context
|
|
341
|
+
* @returns {void}
|
|
342
|
+
*/
|
|
257
343
|
set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
|
|
258
344
|
}
|
|
259
|
-
type DefaultContext = MiddlewareEnabled extends true ? unstable_RouterContextProvider : any;
|
|
345
|
+
type DefaultContext = MiddlewareEnabled extends true ? Readonly<unstable_RouterContextProvider> : any;
|
|
260
346
|
/**
|
|
261
347
|
* @private
|
|
262
348
|
* Arguments passed to route loader/action functions. Same for now but we keep
|
|
@@ -278,7 +364,7 @@ interface DataFunctionArgs<Context> {
|
|
|
278
364
|
* params.teamId;
|
|
279
365
|
* // ^ string
|
|
280
366
|
* }
|
|
281
|
-
|
|
367
|
+
*/
|
|
282
368
|
params: Params;
|
|
283
369
|
/**
|
|
284
370
|
* This is the context passed in to your server adapter's getLoadContext() function.
|
|
@@ -292,7 +378,7 @@ interface DataFunctionArgs<Context> {
|
|
|
292
378
|
* middlewares from the bottom-up
|
|
293
379
|
*/
|
|
294
380
|
interface unstable_MiddlewareNextFunction<Result = unknown> {
|
|
295
|
-
():
|
|
381
|
+
(): Promise<Result>;
|
|
296
382
|
}
|
|
297
383
|
/**
|
|
298
384
|
* Route middleware function signature. Receives the same "data" arguments as a
|
|
@@ -300,7 +386,7 @@ interface unstable_MiddlewareNextFunction<Result = unknown> {
|
|
|
300
386
|
* a `next` function as the second parameter which will call downstream handlers
|
|
301
387
|
* and then complete middlewares from the bottom-up
|
|
302
388
|
*/
|
|
303
|
-
type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<unstable_RouterContextProvider
|
|
389
|
+
type unstable_MiddlewareFunction<Result = unknown> = (args: DataFunctionArgs<Readonly<unstable_RouterContextProvider>>, next: unstable_MiddlewareNextFunction<Result>) => MaybePromise<Result | void>;
|
|
304
390
|
/**
|
|
305
391
|
* Arguments passed to loader functions
|
|
306
392
|
*/
|
|
@@ -406,34 +492,39 @@ interface DataStrategyMatch extends AgnosticRouteMatch<string, AgnosticDataRoute
|
|
|
406
492
|
route: Promise<void> | undefined;
|
|
407
493
|
};
|
|
408
494
|
/**
|
|
409
|
-
* A boolean value indicating whether this route handler should be called in
|
|
495
|
+
* A boolean value indicating whether this route handler should be called in
|
|
496
|
+
* this pass.
|
|
410
497
|
*
|
|
411
|
-
* The `matches` array always includes _all_ matched routes even when only
|
|
412
|
-
* route handlers need to be called so that things like middleware can
|
|
498
|
+
* The `matches` array always includes _all_ matched routes even when only
|
|
499
|
+
* _some_ route handlers need to be called so that things like middleware can
|
|
500
|
+
* be implemented.
|
|
413
501
|
*
|
|
414
|
-
* `shouldLoad` is usually only interesting if you are skipping the route
|
|
415
|
-
* entirely and implementing custom handler logic - since it lets you
|
|
416
|
-
* if that custom logic should run for this route or not.
|
|
502
|
+
* `shouldLoad` is usually only interesting if you are skipping the route
|
|
503
|
+
* handler entirely and implementing custom handler logic - since it lets you
|
|
504
|
+
* determine if that custom logic should run for this route or not.
|
|
417
505
|
*
|
|
418
506
|
* For example:
|
|
419
507
|
* - If you are on `/parent/child/a` and you navigate to `/parent/child/b` -
|
|
420
508
|
* you'll get an array of three matches (`[parent, child, b]`), but only `b`
|
|
421
509
|
* will have `shouldLoad=true` because the data for `parent` and `child` is
|
|
422
510
|
* already loaded
|
|
423
|
-
* - If you are on `/parent/child/a` and you submit to `a`'s `action
|
|
424
|
-
* `a` will have `shouldLoad=true` for the action execution of
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
511
|
+
* - If you are on `/parent/child/a` and you submit to `a`'s [`action`](https://reactrouter.com/docs/start/data/route-object#action),
|
|
512
|
+
* then only `a` will have `shouldLoad=true` for the action execution of
|
|
513
|
+
* `dataStrategy`
|
|
514
|
+
* - After the [`action`](https://reactrouter.com/docs/start/data/route-object#action),
|
|
515
|
+
* `dataStrategy` will be called again for the [`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
|
|
516
|
+
* revalidation, and all matches will have `shouldLoad=true` (assuming no
|
|
517
|
+
* custom `shouldRevalidate` implementations)
|
|
428
518
|
*/
|
|
429
519
|
shouldLoad: boolean;
|
|
430
520
|
unstable_shouldRevalidateArgs: ShouldRevalidateFunctionArgs | null;
|
|
431
521
|
unstable_shouldCallHandler(defaultShouldRevalidate?: boolean): boolean;
|
|
432
522
|
/**
|
|
433
523
|
* An async function that will resolve any `route.lazy` implementations and
|
|
434
|
-
* execute the route's handler (if necessary), returning a
|
|
524
|
+
* execute the route's handler (if necessary), returning a {@link DataStrategyResult}
|
|
435
525
|
*
|
|
436
|
-
* - Calling `match.resolve` does not mean you're calling the
|
|
526
|
+
* - Calling `match.resolve` does not mean you're calling the
|
|
527
|
+
* [`action`](https://reactrouter.com/docs/start/data/route-object#action)/[`loader`](https://reactrouter.com/docs/start/data/route-object#loader)
|
|
437
528
|
* (the "handler") - `resolve` will only call the `handler` internally if
|
|
438
529
|
* needed _and_ if you don't pass your own `handlerOverride` function parameter
|
|
439
530
|
* - It is safe to call `match.resolve` for all matches, even if they have
|
|
@@ -588,7 +679,28 @@ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticData
|
|
|
588
679
|
/**
|
|
589
680
|
* Matches the given routes to a location and returns the match data.
|
|
590
681
|
*
|
|
682
|
+
* @example
|
|
683
|
+
* import { matchRoutes } from "react-router";
|
|
684
|
+
*
|
|
685
|
+
* let routes = [{
|
|
686
|
+
* path: "/",
|
|
687
|
+
* Component: Root,
|
|
688
|
+
* children: [{
|
|
689
|
+
* path: "dashboard",
|
|
690
|
+
* Component: Dashboard,
|
|
691
|
+
* }]
|
|
692
|
+
* }];
|
|
693
|
+
*
|
|
694
|
+
* matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
|
|
695
|
+
*
|
|
696
|
+
* @public
|
|
591
697
|
* @category Utils
|
|
698
|
+
* @param routes The array of route objects to match against.
|
|
699
|
+
* @param locationArg The location to match against, either a string path or a
|
|
700
|
+
* partial {@link Location} object
|
|
701
|
+
* @param basename Optional base path to strip from the location before matching.
|
|
702
|
+
* Defaults to `/`.
|
|
703
|
+
* @returns An array of matched routes, or `null` if no matches were found.
|
|
592
704
|
*/
|
|
593
705
|
declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
|
|
594
706
|
interface UIMatch<Data = unknown, Handle = unknown> {
|
|
@@ -596,11 +708,26 @@ interface UIMatch<Data = unknown, Handle = unknown> {
|
|
|
596
708
|
pathname: string;
|
|
597
709
|
/**
|
|
598
710
|
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
|
|
599
|
-
|
|
711
|
+
*/
|
|
600
712
|
params: AgnosticRouteMatch["params"];
|
|
601
|
-
/**
|
|
602
|
-
|
|
603
|
-
|
|
713
|
+
/**
|
|
714
|
+
* The return value from the matched route's loader or clientLoader. This might
|
|
715
|
+
* be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
|
|
716
|
+
* an error and we're currently displaying an `ErrorBoundary`.
|
|
717
|
+
*
|
|
718
|
+
* @deprecated Use `UIMatch.loaderData` instead
|
|
719
|
+
*/
|
|
720
|
+
data: Data | undefined;
|
|
721
|
+
/**
|
|
722
|
+
* The return value from the matched route's loader or clientLoader. This might
|
|
723
|
+
* be `undefined` if this route's `loader` (or a deeper route's `loader`) threw
|
|
724
|
+
* an error and we're currently displaying an `ErrorBoundary`.
|
|
725
|
+
*/
|
|
726
|
+
loaderData: Data | undefined;
|
|
727
|
+
/**
|
|
728
|
+
* The {@link https://reactrouter.com/start/framework/route-module#handle handle object}
|
|
729
|
+
* exported from the matched route module
|
|
730
|
+
*/
|
|
604
731
|
handle: Handle;
|
|
605
732
|
}
|
|
606
733
|
declare class DataWithResponseInit<D> {
|
|
@@ -610,35 +737,116 @@ declare class DataWithResponseInit<D> {
|
|
|
610
737
|
constructor(data: D, init?: ResponseInit);
|
|
611
738
|
}
|
|
612
739
|
/**
|
|
613
|
-
* Create "responses" that contain `status
|
|
614
|
-
* serialization into an actual `Response`
|
|
740
|
+
* Create "responses" that contain `headers`/`status` without forcing
|
|
741
|
+
* serialization into an actual [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
615
742
|
*
|
|
743
|
+
* @example
|
|
744
|
+
* import { data } from "react-router";
|
|
745
|
+
*
|
|
746
|
+
* export async function action({ request }: Route.ActionArgs) {
|
|
747
|
+
* let formData = await request.formData();
|
|
748
|
+
* let item = await createItem(formData);
|
|
749
|
+
* return data(item, {
|
|
750
|
+
* headers: { "X-Custom-Header": "value" }
|
|
751
|
+
* status: 201,
|
|
752
|
+
* });
|
|
753
|
+
* }
|
|
754
|
+
*
|
|
755
|
+
* @public
|
|
616
756
|
* @category Utils
|
|
757
|
+
* @mode framework
|
|
758
|
+
* @mode data
|
|
759
|
+
* @param data The data to be included in the response.
|
|
760
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
761
|
+
* response.
|
|
762
|
+
* @returns A {@link DataWithResponseInit} instance containing the data and
|
|
763
|
+
* response init.
|
|
617
764
|
*/
|
|
618
765
|
declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
|
|
619
766
|
type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
|
|
620
767
|
/**
|
|
621
|
-
* A redirect
|
|
622
|
-
*
|
|
768
|
+
* A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
|
|
769
|
+
* Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
770
|
+
* header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* import { redirect } from "react-router";
|
|
623
774
|
*
|
|
775
|
+
* export async function loader({ request }: Route.LoaderArgs) {
|
|
776
|
+
* if (!isLoggedIn(request))
|
|
777
|
+
* throw redirect("/login");
|
|
778
|
+
* }
|
|
779
|
+
*
|
|
780
|
+
* // ...
|
|
781
|
+
* }
|
|
782
|
+
*
|
|
783
|
+
* @public
|
|
624
784
|
* @category Utils
|
|
785
|
+
* @mode framework
|
|
786
|
+
* @mode data
|
|
787
|
+
* @param url The URL to redirect to.
|
|
788
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
789
|
+
* response.
|
|
790
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
791
|
+
* object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
792
|
+
* header.
|
|
625
793
|
*/
|
|
626
794
|
declare const redirect$1: RedirectFunction;
|
|
627
795
|
/**
|
|
628
|
-
* A redirect
|
|
629
|
-
*
|
|
630
|
-
*
|
|
796
|
+
* A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
797
|
+
* that will force a document reload to the new location. Sets the status code
|
|
798
|
+
* and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
799
|
+
* header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
|
|
631
800
|
*
|
|
801
|
+
* ```tsx filename=routes/logout.tsx
|
|
802
|
+
* import { redirectDocument } from "react-router";
|
|
803
|
+
*
|
|
804
|
+
* import { destroySession } from "../sessions.server";
|
|
805
|
+
*
|
|
806
|
+
* export async function action({ request }: Route.ActionArgs) {
|
|
807
|
+
* let session = await getSession(request.headers.get("Cookie"));
|
|
808
|
+
* return redirectDocument("/", {
|
|
809
|
+
* headers: { "Set-Cookie": await destroySession(session) }
|
|
810
|
+
* });
|
|
811
|
+
* }
|
|
812
|
+
* ```
|
|
813
|
+
*
|
|
814
|
+
* @public
|
|
632
815
|
* @category Utils
|
|
816
|
+
* @mode framework
|
|
817
|
+
* @mode data
|
|
818
|
+
* @param url The URL to redirect to.
|
|
819
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
820
|
+
* response.
|
|
821
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
822
|
+
* object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
823
|
+
* header.
|
|
633
824
|
*/
|
|
634
825
|
declare const redirectDocument$1: RedirectFunction;
|
|
635
826
|
/**
|
|
636
|
-
* A redirect
|
|
637
|
-
* `history.
|
|
638
|
-
*
|
|
639
|
-
*
|
|
827
|
+
* A redirect [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
828
|
+
* that will perform a [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState)
|
|
829
|
+
* instead of a [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
|
|
830
|
+
* for client-side navigation redirects. Sets the status code and the [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
831
|
+
* header. Defaults to [`302 Found`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302).
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* import { replace } from "react-router";
|
|
835
|
+
*
|
|
836
|
+
* export async function loader() {
|
|
837
|
+
* return replace("/new-location");
|
|
838
|
+
* }
|
|
640
839
|
*
|
|
840
|
+
* @public
|
|
641
841
|
* @category Utils
|
|
842
|
+
* @mode framework
|
|
843
|
+
* @mode data
|
|
844
|
+
* @param url The URL to redirect to.
|
|
845
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
846
|
+
* response.
|
|
847
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
848
|
+
* object with the redirect status and [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location)
|
|
849
|
+
* header.
|
|
642
850
|
*/
|
|
643
851
|
declare const replace$1: RedirectFunction;
|
|
644
852
|
|
|
@@ -916,7 +1124,7 @@ interface RouterInit {
|
|
|
916
1124
|
routes: AgnosticRouteObject[];
|
|
917
1125
|
history: History;
|
|
918
1126
|
basename?: string;
|
|
919
|
-
unstable_getContext?: () => MaybePromise<
|
|
1127
|
+
unstable_getContext?: () => MaybePromise<unstable_RouterContextProvider>;
|
|
920
1128
|
mapRouteProperties?: MapRoutePropertiesFunction;
|
|
921
1129
|
future?: Partial<FutureConfig>;
|
|
922
1130
|
hydrationRouteProperties?: string[];
|
|
@@ -951,14 +1159,13 @@ interface StaticHandler {
|
|
|
951
1159
|
skipLoaderErrorBubbling?: boolean;
|
|
952
1160
|
skipRevalidation?: boolean;
|
|
953
1161
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
954
|
-
|
|
955
|
-
unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
1162
|
+
unstable_generateMiddlewareResponse?: (query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
956
1163
|
}): Promise<StaticHandlerContext | Response>;
|
|
957
1164
|
queryRoute(request: Request, opts?: {
|
|
958
1165
|
routeId?: string;
|
|
959
1166
|
requestContext?: unknown;
|
|
960
1167
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
961
|
-
|
|
1168
|
+
unstable_generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
|
|
962
1169
|
}): Promise<any>;
|
|
963
1170
|
}
|
|
964
1171
|
type ViewTransitionOpts = {
|
|
@@ -1334,7 +1541,13 @@ type HtmlLinkDescriptor = (HtmlLinkProps & Pick<Required<HtmlLinkProps>, "href">
|
|
|
1334
1541
|
});
|
|
1335
1542
|
interface PageLinkDescriptor extends Omit<HtmlLinkDescriptor, "href" | "rel" | "type" | "sizes" | "imageSrcSet" | "imageSizes" | "as" | "color" | "title"> {
|
|
1336
1543
|
/**
|
|
1337
|
-
*
|
|
1544
|
+
* A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
|
|
1545
|
+
* attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
|
|
1546
|
+
* element
|
|
1547
|
+
*/
|
|
1548
|
+
nonce?: string | undefined;
|
|
1549
|
+
/**
|
|
1550
|
+
* The absolute path of the page to prefetch, e.g. `/absolute/path`.
|
|
1338
1551
|
*/
|
|
1339
1552
|
page: string;
|
|
1340
1553
|
}
|
|
@@ -1397,7 +1610,7 @@ type ClientDataFunctionArgs<Params> = {
|
|
|
1397
1610
|
* from your route middlewares. You may pass in initial context values in your
|
|
1398
1611
|
* `<HydratedRouter unstable_getContext>` prop
|
|
1399
1612
|
*/
|
|
1400
|
-
context: unstable_RouterContextProvider
|
|
1613
|
+
context: Readonly<unstable_RouterContextProvider>;
|
|
1401
1614
|
};
|
|
1402
1615
|
type SerializeFrom<T> = T extends (...args: infer Args) => unknown ? Args extends [
|
|
1403
1616
|
ClientLoaderFunctionArgs | ClientActionFunctionArgs | ClientDataFunctionArgs<unknown>
|
|
@@ -1450,7 +1663,9 @@ interface LinksFunction {
|
|
|
1450
1663
|
interface MetaMatch<RouteId extends string = string, Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown> {
|
|
1451
1664
|
id: RouteId;
|
|
1452
1665
|
pathname: DataRouteMatch["pathname"];
|
|
1666
|
+
/** @deprecated Use `MetaMatch.loaderData` instead */
|
|
1453
1667
|
data: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
1668
|
+
loaderData: Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown;
|
|
1454
1669
|
handle?: RouteHandle;
|
|
1455
1670
|
params: DataRouteMatch["params"];
|
|
1456
1671
|
meta: MetaDescriptor[];
|
|
@@ -1460,7 +1675,9 @@ type MetaMatches<MatchLoaders extends Record<string, LoaderFunction | ClientLoad
|
|
|
1460
1675
|
[K in keyof MatchLoaders]: MetaMatch<Exclude<K, number | symbol>, MatchLoaders[K]>;
|
|
1461
1676
|
}[keyof MatchLoaders]>;
|
|
1462
1677
|
interface MetaArgs<Loader extends LoaderFunction | ClientLoaderFunction | unknown = unknown, MatchLoaders extends Record<string, LoaderFunction | ClientLoaderFunction | unknown> = Record<string, unknown>> {
|
|
1678
|
+
/** @deprecated Use `MetaArgs.loaderData` instead */
|
|
1463
1679
|
data: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
|
|
1680
|
+
loaderData: (Loader extends LoaderFunction | ClientLoaderFunction ? SerializeFrom<Loader> : unknown) | undefined;
|
|
1464
1681
|
params: Params;
|
|
1465
1682
|
location: Location;
|
|
1466
1683
|
matches: MetaMatches<MatchLoaders>;
|
|
@@ -1555,12 +1772,6 @@ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
|
1555
1772
|
*/
|
|
1556
1773
|
type RouteHandle = unknown;
|
|
1557
1774
|
|
|
1558
|
-
type ServerContext = {
|
|
1559
|
-
redirect?: Response;
|
|
1560
|
-
};
|
|
1561
|
-
declare global {
|
|
1562
|
-
var ___reactRouterServerStorage___: AsyncLocalStorage<ServerContext> | undefined;
|
|
1563
|
-
}
|
|
1564
1775
|
declare const redirect: typeof redirect$1;
|
|
1565
1776
|
declare const redirectDocument: typeof redirectDocument$1;
|
|
1566
1777
|
declare const replace: typeof replace$1;
|
|
@@ -1661,8 +1872,11 @@ type DecodeReplyFunction = (reply: FormData | string, { temporaryReferences }: {
|
|
|
1661
1872
|
}) => Promise<unknown[]>;
|
|
1662
1873
|
type LoadServerActionFunction = (id: string) => Promise<Function>;
|
|
1663
1874
|
/**
|
|
1664
|
-
* Matches the given routes to a Request
|
|
1665
|
-
*
|
|
1875
|
+
* Matches the given routes to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
1876
|
+
* and returns an [RSC](https://react.dev/reference/rsc/server-components)
|
|
1877
|
+
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
1878
|
+
* encoding an {@link unstable_RSCPayload} for consumption by an [RSC](https://react.dev/reference/rsc/server-components)
|
|
1879
|
+
* enabled client router.
|
|
1666
1880
|
*
|
|
1667
1881
|
* @example
|
|
1668
1882
|
* import {
|
|
@@ -1699,27 +1913,33 @@ type LoadServerActionFunction = (id: string) => Promise<Function>;
|
|
|
1699
1913
|
* @mode data
|
|
1700
1914
|
* @param opts Options
|
|
1701
1915
|
* @param opts.basename The basename to use when matching the request.
|
|
1916
|
+
* @param opts.createTemporaryReferenceSet A function that returns a temporary
|
|
1917
|
+
* reference set for the request, used to track temporary references in the [RSC](https://react.dev/reference/rsc/server-components)
|
|
1918
|
+
* stream.
|
|
1702
1919
|
* @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
|
|
1703
1920
|
* function, responsible for loading a server action.
|
|
1921
|
+
* @param opts.decodeFormState A function responsible for decoding form state for
|
|
1922
|
+
* progressively enhanceable forms with React's [`useActionState`](https://react.dev/reference/react/useActionState)
|
|
1923
|
+
* using your `react-server-dom-xyz/server`'s `decodeFormState`.
|
|
1704
1924
|
* @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
|
|
1705
1925
|
* function, used to decode the server function's arguments and bind them to the
|
|
1706
1926
|
* implementation for invocation by the router.
|
|
1707
|
-
* @param opts.decodeFormState A function responsible for decoding form state for
|
|
1708
|
-
* progressively enhanceable forms with `useActionState` using your
|
|
1709
|
-
* `react-server-dom-xyz/server`'s `decodeFormState`.
|
|
1710
1927
|
* @param opts.generateResponse A function responsible for using your
|
|
1711
|
-
* `renderToReadableStream` to generate a Response
|
|
1928
|
+
* `renderToReadableStream` to generate a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
1929
|
+
* encoding the {@link unstable_RSCPayload}.
|
|
1712
1930
|
* @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
|
|
1713
1931
|
* `loadServerAction` function, used to load a server action by ID.
|
|
1714
|
-
* @param opts.request The request to match against.
|
|
1715
|
-
* @param opts.requestContext An instance of `unstable_RouterContextProvider`
|
|
1716
|
-
* that should be created per request, to be passed to loaders, actions and middleware.
|
|
1717
|
-
* @param opts.routes Your route definitions.
|
|
1718
|
-
* @param opts.createTemporaryReferenceSet A function that returns a temporary
|
|
1719
|
-
* reference set for the request, used to track temporary references in the RSC stream.
|
|
1720
1932
|
* @param opts.onError An optional error handler that will be called with any
|
|
1721
1933
|
* errors that occur during the request processing.
|
|
1722
|
-
* @
|
|
1934
|
+
* @param opts.request The [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
1935
|
+
* to match against.
|
|
1936
|
+
* @param opts.requestContext An instance of {@link unstable_RouterContextProvider}
|
|
1937
|
+
* that should be created per request, to be passed to [`action`](../../start/data/route-object#action)s,
|
|
1938
|
+
* [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
|
|
1939
|
+
* @param opts.routes Your {@link unstable_RSCRouteConfigEntry | route definitions}.
|
|
1940
|
+
* @returns A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
1941
|
+
* that contains the [RSC](https://react.dev/reference/rsc/server-components)
|
|
1942
|
+
* data for hydration.
|
|
1723
1943
|
*/
|
|
1724
1944
|
declare function matchRSCServerRequest({ createTemporaryReferenceSet, basename, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
|
|
1725
1945
|
createTemporaryReferenceSet: () => unknown;
|