react-router 0.0.0-experimental-2a6c7bc → 0.0.0-experimental-e89ad3012
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/dist/development/{chunk-VEWXUMGM.mjs → chunk-3O4L5GVQ.mjs} +90 -125
- package/dist/development/{chunk-JRLTRGBE.js → chunk-JJHCVRDZ.js} +89 -124
- package/dist/development/{chunk-GSZ4XTPZ.js → chunk-ROJMZUUV.js} +130 -130
- package/dist/{production/chunk-ATNMTWNA.mjs → development/chunk-XKV32KFX.mjs} +157 -141
- package/dist/development/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
- package/dist/development/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
- package/dist/development/dom-export.d.mts +3 -3
- package/dist/development/dom-export.d.ts +1 -1
- package/dist/development/dom-export.js +3 -3
- package/dist/development/dom-export.mjs +3 -3
- package/dist/{production/index-react-server-client-DIZWnqdE.d.ts → development/index-react-server-client-D-lyvxf_.d.ts} +25 -26
- package/dist/{production/index-react-server-client-BuCmY0hu.d.mts → development/index-react-server-client-pe1TAKAq.d.mts} +12 -13
- package/dist/development/index-react-server-client.d.mts +4 -4
- 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 +193 -14
- package/dist/development/index-react-server.d.ts +193 -14
- package/dist/development/index-react-server.js +115 -147
- package/dist/development/index-react-server.mjs +115 -147
- package/dist/development/index.d.mts +8 -8
- package/dist/development/index.d.ts +4 -4
- package/dist/development/index.js +240 -224
- package/dist/development/index.mjs +3 -3
- package/dist/development/lib/types/internal.d.mts +2 -2
- package/dist/development/lib/types/internal.d.ts +1 -1
- package/dist/development/lib/types/internal.js +1 -1
- package/dist/development/lib/types/internal.mjs +1 -1
- package/dist/development/{route-data-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
- package/dist/development/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
- package/dist/{development/chunk-M2KD4YIT.mjs → production/chunk-J6PLTU3O.mjs} +157 -141
- package/dist/production/{chunk-3UOGQQWX.js → chunk-NFNPXIQE.js} +89 -124
- package/dist/production/{chunk-P2JVUBYL.mjs → chunk-QI3NR5VQ.mjs} +90 -125
- package/dist/production/{chunk-ZIOZTUIH.js → chunk-X3M2F3OK.js} +130 -130
- package/dist/production/{components-CFzgj3gZ.d.mts → components-BkK38HPd.d.mts} +16 -16
- package/dist/production/{context-AvZz33Zq.d.mts → context-CphUWOpx.d.mts} +238 -22
- package/dist/production/dom-export.d.mts +3 -3
- package/dist/production/dom-export.d.ts +1 -1
- package/dist/production/dom-export.js +3 -3
- package/dist/production/dom-export.mjs +3 -3
- package/dist/{development/index-react-server-client-DIZWnqdE.d.ts → production/index-react-server-client-D-lyvxf_.d.ts} +25 -26
- package/dist/{development/index-react-server-client-BuCmY0hu.d.mts → production/index-react-server-client-pe1TAKAq.d.mts} +12 -13
- package/dist/production/index-react-server-client.d.mts +4 -4
- 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 +193 -14
- package/dist/production/index-react-server.d.ts +193 -14
- package/dist/production/index-react-server.js +115 -147
- package/dist/production/index-react-server.mjs +115 -147
- package/dist/production/index.d.mts +8 -8
- package/dist/production/index.d.ts +4 -4
- package/dist/production/index.js +240 -224
- package/dist/production/index.mjs +3 -3
- package/dist/production/lib/types/internal.d.mts +2 -2
- package/dist/production/lib/types/internal.d.ts +1 -1
- package/dist/production/lib/types/internal.js +1 -1
- package/dist/production/lib/types/internal.mjs +1 -1
- package/dist/production/{route-data-BnrIwdAP.d.mts → route-data-DJXZgnJq.d.mts} +1 -1
- package/dist/production/{routeModules-BbH0xTnc.d.ts → routeModules-DH3xUx4Z.d.ts} +238 -22
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import './components-
|
|
1
|
+
import './components-BkK38HPd.mjs';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { az as RouteManifest, M as MiddlewareEnabled, o as unstable_RouterContextProvider, j as LoaderFunctionArgs, i as ActionFunctionArgs, J as StaticHandlerContext, H as HydrationState, z as DataRouteObject, a2 as HTMLFormMethod, a0 as FormEncType, a as RelativeRoutingType, T as To, aA as History, E as GetScrollRestorationKeyFunction, e as RouterInit, F as FutureConfig$1, D as DataStrategyFunction, P as PatchRoutesOnNavigationFunction, q as NavigateOptions, K as Fetcher, f as RouteObject, R as Router, B as BlockerFunction, c as Location, aB as CreateStaticHandlerOptions$1, C as StaticHandler } from './context-
|
|
4
|
-
import { o as ServerRouteModule, A as AppLoadContext, c as RouteModules, h as ClientLoaderFunction, m as PageLinkDescriptor, d as SerializeFrom } from './route-data-
|
|
3
|
+
import { az as RouteManifest, M as MiddlewareEnabled, o as unstable_RouterContextProvider, j as LoaderFunctionArgs, i as ActionFunctionArgs, J as StaticHandlerContext, H as HydrationState, z as DataRouteObject, a2 as HTMLFormMethod, a0 as FormEncType, a as RelativeRoutingType, T as To, aA as History, E as GetScrollRestorationKeyFunction, e as RouterInit, F as FutureConfig$1, D as DataStrategyFunction, P as PatchRoutesOnNavigationFunction, q as NavigateOptions, K as Fetcher, f as RouteObject, R as Router, B as BlockerFunction, c as Location, aB as CreateStaticHandlerOptions$1, C as StaticHandler } from './context-CphUWOpx.mjs';
|
|
4
|
+
import { o as ServerRouteModule, A as AppLoadContext, c as RouteModules, h as ClientLoaderFunction, m as PageLinkDescriptor, d as SerializeFrom } from './route-data-DJXZgnJq.mjs';
|
|
5
5
|
|
|
6
6
|
type ServerRouteManifest = RouteManifest<Omit<ServerRoute, "children">>;
|
|
7
7
|
interface ServerRoute extends Route {
|
|
@@ -463,7 +463,7 @@ interface DOMRouterOpts {
|
|
|
463
463
|
* [`clientLoader`](../../start/framework/route-module#clientLoader)), you may
|
|
464
464
|
* want to include `loaderData` for only some routes that were loaded/rendered
|
|
465
465
|
* on the server. This allows you to hydrate _some_ of the routes (such as the
|
|
466
|
-
* app layout/shell) while showing a
|
|
466
|
+
* app layout/shell) while showing a `HydrateFallback`
|
|
467
467
|
* component and running the [`loader`](../../start/data/route-object#loader)s
|
|
468
468
|
* for other routes during hydration.
|
|
469
469
|
*
|
|
@@ -471,8 +471,7 @@ interface DOMRouterOpts {
|
|
|
471
471
|
* hydration in two scenarios:
|
|
472
472
|
*
|
|
473
473
|
* 1. No hydration data is provided
|
|
474
|
-
* In these cases the
|
|
475
|
-
* component will render on initial hydration
|
|
474
|
+
* In these cases the `HydrateFallback` component will render on initial hydration
|
|
476
475
|
* 2. The `loader.hydrate` property is set to `true`
|
|
477
476
|
* This allows you to run the [`loader`](../../start/data/route-object#loader)
|
|
478
477
|
* even if you did not render a fallback on initial hydration (i.e., to
|
|
@@ -534,9 +533,9 @@ interface DOMRouterOpts {
|
|
|
534
533
|
*
|
|
535
534
|
* The `dataStrategy` function should return a key/value-object of
|
|
536
535
|
* `routeId` -> {@link DataStrategyResult} and should include entries for any
|
|
537
|
-
* routes where a handler was executed. A
|
|
538
|
-
* if the handler was successful or not based on the
|
|
539
|
-
* field. If the returned
|
|
536
|
+
* routes where a handler was executed. A `DataStrategyResult` indicates
|
|
537
|
+
* if the handler was successful or not based on the `DataStrategyResult.type`
|
|
538
|
+
* field. If the returned `DataStrategyResult.result` is a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response),
|
|
540
539
|
* React Router will unwrap it for you (via [`res.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json)
|
|
541
540
|
* or [`res.text`](https://developer.mozilla.org/en-US/docs/Web/API/Response/text)).
|
|
542
541
|
* If you need to do custom decoding of a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
@@ -556,7 +555,7 @@ interface DOMRouterOpts {
|
|
|
556
555
|
* let router = createBrowserRouter(routes, {
|
|
557
556
|
* async dataStrategy({ matches, request }) {
|
|
558
557
|
* const matchesToLoad = matches.filter((m) => m.shouldLoad);
|
|
559
|
-
* const results = {};
|
|
558
|
+
* const results: Record<string, DataStrategyResult> = {};
|
|
560
559
|
* await Promise.all(
|
|
561
560
|
* matchesToLoad.map(async (match) => {
|
|
562
561
|
* console.log(`Processing ${match.route.id}`);
|
|
@@ -730,7 +729,7 @@ interface DOMRouterOpts {
|
|
|
730
729
|
*
|
|
731
730
|
* `patchRoutesOnNavigation` will be called anytime React Router is unable to
|
|
732
731
|
* match a `path`. The arguments include the `path`, any partial
|
|
733
|
-
*
|
|
732
|
+
* `matches`, and a `patch` function you can call to patch
|
|
734
733
|
* new routes into the tree at a specific location. This method is executed
|
|
735
734
|
* during the `loading` portion of the navigation for `GET` requests and during
|
|
736
735
|
* the `submitting` portion of the navigation for non-`GET` requests.
|
|
@@ -833,7 +832,7 @@ interface DOMRouterOpts {
|
|
|
833
832
|
* **Co-locating route discovery with route definition**
|
|
834
833
|
*
|
|
835
834
|
* If you don't wish to perform your own pseudo-matching, you can leverage
|
|
836
|
-
* the partial
|
|
835
|
+
* the partial `matches` array and the [`handle`](../../start/data/route-object#handle)
|
|
837
836
|
* field on a route to keep the children definitions co-located:
|
|
838
837
|
*
|
|
839
838
|
* ```tsx
|
|
@@ -2484,4 +2483,4 @@ declare function createStaticRouter(routes: RouteObject[], context: StaticHandle
|
|
|
2484
2483
|
future?: Partial<FutureConfig$1>;
|
|
2485
2484
|
}): Router;
|
|
2486
2485
|
|
|
2487
|
-
export { type
|
|
2486
|
+
export { type ScriptsProps as $, type AssetsManifest as A, type BrowserRouterProps as B, useViewTransitionState as C, type DOMRouterOpts as D, type EntryContext as E, type FutureConfig as F, type FetcherSubmitOptions as G, type HashRouterProps as H, type SubmitOptions as I, type SubmitTarget as J, createSearchParams as K, type LinkProps as L, type StaticRouterProps as M, type NavLinkProps as N, type StaticRouterProviderProps as O, type ParamKeyValuePair as P, createStaticHandler as Q, createStaticRouter as R, type ServerBuild as S, StaticRouter as T, type URLSearchParamsInit as U, StaticRouterProvider as V, Meta as W, Links as X, Scripts as Y, PrefetchPageLinks as Z, type LinksProps as _, type HistoryRouterProps as a, type PrefetchBehavior as a0, type DiscoverBehavior as a1, type HandleDataRequestFunction as a2, type HandleDocumentRequestFunction as a3, type HandleErrorFunction as a4, type ServerEntryModule as a5, FrameworkContext as a6, createClientRoutes as a7, createClientRoutesWithHMRRevalidationOptOut as a8, shouldHydrateRouteLoader as a9, useScrollRestoration as aa, type NavLinkRenderProps as b, type FetcherFormProps as c, type FormProps as d, type ScrollRestorationProps as e, type SetURLSearchParams as f, type SubmitFunction as g, type FetcherSubmitFunction as h, type FetcherWithComponents as i, createBrowserRouter as j, createHashRouter as k, BrowserRouter as l, HashRouter as m, Link as n, HistoryRouter as o, NavLink as p, Form as q, ScrollRestoration as r, useSearchParams as s, useSubmit as t, useLinkClickHandler as u, useFormAction as v, useFetcher as w, useFetchers as x, useBeforeUnload as y, usePrompt as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { f as Await, g as MemoryRouter, h as Navigate, i as Outlet, j as Route, k as Router, l as RouterProvider, m as Routes, W as UNSAFE_WithComponentProps, v as UNSAFE_WithErrorBoundaryProps, t as UNSAFE_WithHydrateFallbackProps } from './components-
|
|
2
|
-
export { l as BrowserRouter, q as Form, m as HashRouter, n as Link, X as Links, W as Meta, p as NavLink, r as ScrollRestoration, T as StaticRouter, V as StaticRouterProvider, o as unstable_HistoryRouter } from './index-react-server-client-
|
|
3
|
-
import './context-
|
|
1
|
+
export { f as Await, g as MemoryRouter, h as Navigate, i as Outlet, j as Route, k as Router, l as RouterProvider, m as Routes, W as UNSAFE_WithComponentProps, v as UNSAFE_WithErrorBoundaryProps, t as UNSAFE_WithHydrateFallbackProps } from './components-BkK38HPd.mjs';
|
|
2
|
+
export { l as BrowserRouter, q as Form, m as HashRouter, n as Link, X as Links, W as Meta, p as NavLink, r as ScrollRestoration, T as StaticRouter, V as StaticRouterProvider, o as unstable_HistoryRouter } from './index-react-server-client-pe1TAKAq.mjs';
|
|
3
|
+
import './context-CphUWOpx.mjs';
|
|
4
4
|
import 'react';
|
|
5
|
-
import './route-data-
|
|
5
|
+
import './route-data-DJXZgnJq.mjs';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { h as Await, V as BrowserRouter, _ as Form, W as HashRouter, X as Link, am as Links, i as MemoryRouter, al as Meta, Z as NavLink, j as Navigate, k as Outlet, l as Route, m as Router, n as RouterProvider, o as Routes, $ as ScrollRestoration, aj as StaticRouter, ak as StaticRouterProvider,
|
|
2
|
-
import './routeModules-
|
|
1
|
+
export { h as Await, V as BrowserRouter, _ as Form, W as HashRouter, X as Link, am as Links, i as MemoryRouter, al as Meta, Z as NavLink, j as Navigate, k as Outlet, l as Route, m as Router, n as RouterProvider, o as Routes, $ as ScrollRestoration, aj as StaticRouter, ak as StaticRouterProvider, az as UNSAFE_WithComponentProps, aD as UNSAFE_WithErrorBoundaryProps, aB as UNSAFE_WithHydrateFallbackProps, Y as unstable_HistoryRouter } from './index-react-server-client-D-lyvxf_.js';
|
|
2
|
+
import './routeModules-DH3xUx4Z.js';
|
|
3
3
|
import 'react';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-e89ad3012
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
var
|
|
33
|
+
var _chunkROJMZUUVjs = require('./chunk-ROJMZUUV.js');
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
var
|
|
37
|
+
var _chunkJJHCVRDZjs = require('./chunk-JJHCVRDZ.js');
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
|
|
@@ -58,4 +58,4 @@ var _chunkJRLTRGBEjs = require('./chunk-JRLTRGBE.js');
|
|
|
58
58
|
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
exports.Await =
|
|
61
|
+
exports.Await = _chunkROJMZUUVjs.Await; exports.BrowserRouter = _chunkROJMZUUVjs.BrowserRouter; exports.Form = _chunkROJMZUUVjs.Form; exports.HashRouter = _chunkROJMZUUVjs.HashRouter; exports.Link = _chunkROJMZUUVjs.Link; exports.Links = _chunkJJHCVRDZjs.Links; exports.MemoryRouter = _chunkROJMZUUVjs.MemoryRouter; exports.Meta = _chunkJJHCVRDZjs.Meta; exports.NavLink = _chunkROJMZUUVjs.NavLink; exports.Navigate = _chunkROJMZUUVjs.Navigate; exports.Outlet = _chunkROJMZUUVjs.Outlet; exports.Route = _chunkROJMZUUVjs.Route; exports.Router = _chunkROJMZUUVjs.Router; exports.RouterProvider = _chunkROJMZUUVjs.RouterProvider; exports.Routes = _chunkROJMZUUVjs.Routes; exports.ScrollRestoration = _chunkROJMZUUVjs.ScrollRestoration; exports.StaticRouter = _chunkROJMZUUVjs.StaticRouter; exports.StaticRouterProvider = _chunkROJMZUUVjs.StaticRouterProvider; exports.UNSAFE_WithComponentProps = _chunkROJMZUUVjs.WithComponentProps; exports.UNSAFE_WithErrorBoundaryProps = _chunkROJMZUUVjs.WithErrorBoundaryProps; exports.UNSAFE_WithHydrateFallbackProps = _chunkROJMZUUVjs.WithHydrateFallbackProps; exports.unstable_HistoryRouter = _chunkROJMZUUVjs.HistoryRouter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* react-router v0.0.0-experimental-
|
|
2
|
+
* react-router v0.0.0-experimental-e89ad3012
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
WithComponentProps,
|
|
33
33
|
WithErrorBoundaryProps,
|
|
34
34
|
WithHydrateFallbackProps
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-3O4L5GVQ.mjs";
|
|
36
36
|
export {
|
|
37
37
|
Await,
|
|
38
38
|
BrowserRouter,
|
|
@@ -227,27 +227,117 @@ type Submission = {
|
|
|
227
227
|
json: undefined;
|
|
228
228
|
text: string;
|
|
229
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
|
+
*/
|
|
230
235
|
interface unstable_RouterContext<T = unknown> {
|
|
231
236
|
defaultValue?: T;
|
|
232
237
|
}
|
|
233
238
|
/**
|
|
234
|
-
* Creates a context object that
|
|
239
|
+
* Creates a type-safe context object that can be used to store and retrieve
|
|
240
|
+
* values in middleware, [loaders](../../start/framework/route-module#loader),
|
|
241
|
+
* and [actions](../../start/framework/route-module#action). Similar to React's
|
|
242
|
+
* [`createContext`](https://react.dev/reference/react/createContext), but
|
|
243
|
+
* designed for React Router's request/response lifecycle.
|
|
244
|
+
*
|
|
245
|
+
* If a `defaultValue` is provided, it will be returned from `context.get()` when
|
|
246
|
+
* no value has been set for the context. Otherwise reading this context when no
|
|
247
|
+
* value has been set will throw an error.
|
|
235
248
|
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
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 { userContext } from "~/context";
|
|
259
|
+
* import { getUserFromSession } from "~/auth.server";
|
|
260
|
+
*
|
|
261
|
+
* export const authMiddleware = async ({
|
|
262
|
+
* request,
|
|
263
|
+
* context,
|
|
264
|
+
* }) => {
|
|
265
|
+
* const user = await getUserFromSession(request);
|
|
266
|
+
* context.set(userContext, user);
|
|
267
|
+
* };
|
|
268
|
+
* ```
|
|
239
269
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
270
|
+
* ```tsx filename=app/routes/profile.tsx
|
|
271
|
+
* import { userContext } from "~/context";
|
|
272
|
+
*
|
|
273
|
+
* export async function loader({
|
|
274
|
+
* context,
|
|
275
|
+
* }: Route.LoaderArgs) {
|
|
276
|
+
* const user = context.get(userContext);
|
|
277
|
+
*
|
|
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 will
|
|
291
|
+
* 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 middleware, loaders, and actions.
|
|
242
294
|
*/
|
|
243
295
|
declare function unstable_createContext<T>(defaultValue?: T): unstable_RouterContext<T>;
|
|
244
296
|
/**
|
|
245
|
-
* Provides methods for writing/reading values in application context in a
|
|
297
|
+
* Provides methods for writing/reading values in application context in a
|
|
298
|
+
* type-safe way. Primarily for usage with [Middleware](../../how-to/middleware).
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* import {
|
|
302
|
+
* unstable_createContext,
|
|
303
|
+
* unstable_RouterContextProvider
|
|
304
|
+
* } from "react-router";
|
|
305
|
+
*
|
|
306
|
+
* const userContext = unstable_createContext<User | null>(null);
|
|
307
|
+
* const contextProvider = new unstable_RouterContextProvider();
|
|
308
|
+
* contextProvider.set(userContext, getUser());
|
|
309
|
+
* const user = contextProvider.get(userContext);
|
|
310
|
+
* // ^ User
|
|
311
|
+
*
|
|
312
|
+
* @public
|
|
313
|
+
* @category Utils
|
|
314
|
+
* @mode framework
|
|
315
|
+
* @mode data
|
|
246
316
|
*/
|
|
247
317
|
declare class unstable_RouterContextProvider {
|
|
248
318
|
#private;
|
|
319
|
+
/**
|
|
320
|
+
* Create a new `unstable_RouterContextProvider` instance
|
|
321
|
+
* @param init An optional initial context map to populate the provider with
|
|
322
|
+
*/
|
|
249
323
|
constructor(init?: Map<unstable_RouterContext, unknown>);
|
|
324
|
+
/**
|
|
325
|
+
* Access a value from the context. If no value has been set for the
|
|
326
|
+
* context, it will return the context's `defaultValue` if provided, or throw an
|
|
327
|
+
* error if no `defaultValue` was set.
|
|
328
|
+
* @param context The context to get the value for
|
|
329
|
+
* @returns The value for the context, or the contexts `defaultValue` if no
|
|
330
|
+
* value was set
|
|
331
|
+
*/
|
|
250
332
|
get<T>(context: unstable_RouterContext<T>): T;
|
|
333
|
+
/**
|
|
334
|
+
* Set a value for the context. If the context already has a value set,
|
|
335
|
+
* this will overwrite it.
|
|
336
|
+
*
|
|
337
|
+
* @param context The context to set the value for
|
|
338
|
+
* @param value The value to set for the context
|
|
339
|
+
* @returns {void}
|
|
340
|
+
*/
|
|
251
341
|
set<C extends unstable_RouterContext>(context: C, value: C extends unstable_RouterContext<infer T> ? T : never): void;
|
|
252
342
|
}
|
|
253
343
|
type DefaultContext = MiddlewareEnabled extends true ? Readonly<unstable_RouterContextProvider> : any;
|
|
@@ -272,7 +362,7 @@ interface DataFunctionArgs<Context> {
|
|
|
272
362
|
* params.teamId;
|
|
273
363
|
* // ^ string
|
|
274
364
|
* }
|
|
275
|
-
|
|
365
|
+
*/
|
|
276
366
|
params: Params;
|
|
277
367
|
/**
|
|
278
368
|
* This is the context passed in to your server adapter's getLoadContext() function.
|
|
@@ -587,7 +677,27 @@ interface AgnosticDataRouteMatch extends AgnosticRouteMatch<string, AgnosticData
|
|
|
587
677
|
/**
|
|
588
678
|
* Matches the given routes to a location and returns the match data.
|
|
589
679
|
*
|
|
680
|
+
* @example
|
|
681
|
+
* import { matchRoutes } from "react-router";
|
|
682
|
+
*
|
|
683
|
+
* let routes = [{
|
|
684
|
+
* path: "/",
|
|
685
|
+
* Component: Root,
|
|
686
|
+
* children: [{
|
|
687
|
+
* path: "dashboard",
|
|
688
|
+
* Component: Dashboard,
|
|
689
|
+
* }]
|
|
690
|
+
* }];
|
|
691
|
+
*
|
|
692
|
+
* matchRoutes(routes, "/dashboard"); // [rootMatch, dashboardMatch]
|
|
693
|
+
*
|
|
694
|
+
* @public
|
|
590
695
|
* @category Utils
|
|
696
|
+
* @param routes The array of route objects to match against.
|
|
697
|
+
* @param locationArg The location to match against, either a string path or a
|
|
698
|
+
* partial {@link Location} object
|
|
699
|
+
* @param basename Optional base path to strip from the location before matching.
|
|
700
|
+
* @returns An array of matched routes, or `null` if no matches were found.
|
|
591
701
|
*/
|
|
592
702
|
declare function matchRoutes<RouteObjectType extends AgnosticRouteObject = AgnosticRouteObject>(routes: RouteObjectType[], locationArg: Partial<Location> | string, basename?: string): AgnosticRouteMatch<string, RouteObjectType>[] | null;
|
|
593
703
|
interface UIMatch<Data = unknown, Handle = unknown> {
|
|
@@ -595,7 +705,7 @@ interface UIMatch<Data = unknown, Handle = unknown> {
|
|
|
595
705
|
pathname: string;
|
|
596
706
|
/**
|
|
597
707
|
* {@link https://reactrouter.com/start/framework/routing#dynamic-segments Dynamic route params} for the matched route.
|
|
598
|
-
|
|
708
|
+
*/
|
|
599
709
|
params: AgnosticRouteMatch["params"];
|
|
600
710
|
/**
|
|
601
711
|
* The return value from the matched route's loader or clientLoader
|
|
@@ -616,9 +726,29 @@ declare class DataWithResponseInit<D> {
|
|
|
616
726
|
}
|
|
617
727
|
/**
|
|
618
728
|
* Create "responses" that contain `status`/`headers` without forcing
|
|
619
|
-
* serialization into an actual `Response`
|
|
729
|
+
* serialization into an actual `Response`
|
|
620
730
|
*
|
|
731
|
+
* @example
|
|
732
|
+
* import { data } from "react-router";
|
|
733
|
+
*
|
|
734
|
+
* export async function action({ request }) {
|
|
735
|
+
* let formData = await request.formData();
|
|
736
|
+
* let item = await createItem(formData);
|
|
737
|
+
* return data(item, {
|
|
738
|
+
* status: 201,
|
|
739
|
+
* headers: { "X-Custom-Header": "value" }
|
|
740
|
+
* });
|
|
741
|
+
* }
|
|
742
|
+
*
|
|
743
|
+
* @public
|
|
621
744
|
* @category Utils
|
|
745
|
+
* @mode framework
|
|
746
|
+
* @mode data
|
|
747
|
+
* @param data The data to be included in the response.
|
|
748
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
749
|
+
* response.
|
|
750
|
+
* @returns A `DataWithResponseInit` instance containing the data and response
|
|
751
|
+
* init.
|
|
622
752
|
*/
|
|
623
753
|
declare function data<D>(data: D, init?: number | ResponseInit): DataWithResponseInit<D>;
|
|
624
754
|
type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
|
|
@@ -626,7 +756,25 @@ type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
|
|
|
626
756
|
* A redirect response. Sets the status code and the `Location` header.
|
|
627
757
|
* Defaults to "302 Found".
|
|
628
758
|
*
|
|
759
|
+
* @example
|
|
760
|
+
* import { redirect } from "react-router";
|
|
761
|
+
*
|
|
762
|
+
* export function loader({ request }) {
|
|
763
|
+
* if (!isLoggedIn(request))
|
|
764
|
+
* throw redirect("/login");
|
|
765
|
+
* }
|
|
766
|
+
*
|
|
767
|
+
* // ...
|
|
768
|
+
* }
|
|
769
|
+
*
|
|
770
|
+
* @public
|
|
629
771
|
* @category Utils
|
|
772
|
+
* @mode framework
|
|
773
|
+
* @mode data
|
|
774
|
+
* @param url The URL to redirect to.
|
|
775
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
776
|
+
* response.
|
|
777
|
+
* @returns A `Response` object with the redirect status and `Location` header.
|
|
630
778
|
*/
|
|
631
779
|
declare const redirect$1: RedirectFunction;
|
|
632
780
|
/**
|
|
@@ -634,7 +782,26 @@ declare const redirect$1: RedirectFunction;
|
|
|
634
782
|
* Sets the status code and the `Location` header.
|
|
635
783
|
* Defaults to "302 Found".
|
|
636
784
|
*
|
|
785
|
+
* @example
|
|
786
|
+
* // routes/logout.tsx
|
|
787
|
+
* import { redirectDocument } from "react-router";
|
|
788
|
+
* import { destroySession } from "../sessions.server";
|
|
789
|
+
*
|
|
790
|
+
* export async function action({ request }) {
|
|
791
|
+
* let session = await getSession(request.headers.get("Cookie"));
|
|
792
|
+
* return redirectDocument("/", {
|
|
793
|
+
* headers: { "Set-Cookie": await destroySession(session) }
|
|
794
|
+
* });
|
|
795
|
+
* }
|
|
796
|
+
*
|
|
797
|
+
* @public
|
|
637
798
|
* @category Utils
|
|
799
|
+
* @mode framework
|
|
800
|
+
* @mode data
|
|
801
|
+
* @param url The URL to redirect to.
|
|
802
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
803
|
+
* response.
|
|
804
|
+
* @returns A `Response` object with the redirect status and `Location` header.
|
|
638
805
|
*/
|
|
639
806
|
declare const redirectDocument$1: RedirectFunction;
|
|
640
807
|
/**
|
|
@@ -643,7 +810,21 @@ declare const redirectDocument$1: RedirectFunction;
|
|
|
643
810
|
* Sets the status code and the `Location` header.
|
|
644
811
|
* Defaults to "302 Found".
|
|
645
812
|
*
|
|
813
|
+
* @example
|
|
814
|
+
* import { replace } from "react-router";
|
|
815
|
+
*
|
|
816
|
+
* export function loader() {
|
|
817
|
+
* return replace("/new-location");
|
|
818
|
+
* }
|
|
819
|
+
*
|
|
820
|
+
* @public
|
|
646
821
|
* @category Utils
|
|
822
|
+
* @mode framework
|
|
823
|
+
* @mode data
|
|
824
|
+
* @param url The URL to redirect to.
|
|
825
|
+
* @param init The status code or a `ResponseInit` object to be included in the
|
|
826
|
+
* response.
|
|
827
|
+
* @returns A `Response` object with the redirect status and `Location` header.
|
|
647
828
|
*/
|
|
648
829
|
declare const replace$1: RedirectFunction;
|
|
649
830
|
|
|
@@ -956,15 +1137,13 @@ interface StaticHandler {
|
|
|
956
1137
|
skipLoaderErrorBubbling?: boolean;
|
|
957
1138
|
skipRevalidation?: boolean;
|
|
958
1139
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
959
|
-
|
|
960
|
-
unstable_stream?: (context: unstable_RouterContextProvider, query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
1140
|
+
unstable_generateMiddlewareResponse?: (query: (r: Request) => Promise<StaticHandlerContext | Response>) => MaybePromise<Response>;
|
|
961
1141
|
}): Promise<StaticHandlerContext | Response>;
|
|
962
1142
|
queryRoute(request: Request, opts?: {
|
|
963
1143
|
routeId?: string;
|
|
964
1144
|
requestContext?: unknown;
|
|
965
1145
|
dataStrategy?: DataStrategyFunction<unknown>;
|
|
966
|
-
|
|
967
|
-
unstable_stream?: (context: unstable_RouterContextProvider, queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
|
|
1146
|
+
unstable_generateMiddlewareResponse?: (queryRoute: (r: Request) => Promise<Response>) => MaybePromise<Response>;
|
|
968
1147
|
}): Promise<any>;
|
|
969
1148
|
}
|
|
970
1149
|
type ViewTransitionOpts = {
|