react-router 7.7.0 → 7.7.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 +11 -23
- package/dist/development/{browser-CcxeZJcQ.d.mts → browser-7LYX59NK.d.mts} +97 -1
- package/dist/development/{chunk-EF7DTUVF.mjs → chunk-C37GKA54.mjs} +83 -80
- package/dist/development/{chunk-V6PEDDZI.js → chunk-K7YFBME3.js} +79 -76
- package/dist/{production/chunk-GNZILI6H.mjs → development/chunk-KIUJAIYX.mjs} +3 -5
- package/dist/{production/chunk-2TYFPE3B.js → development/chunk-R73PQUJU.js} +132 -132
- package/dist/development/components-CjQijYga.d.mts +802 -0
- package/dist/development/dom-export.d.mts +13 -6
- package/dist/development/dom-export.d.ts +10 -3
- 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 +3163 -0
- package/dist/development/index-react-server-client-KLg-U4nr.d.mts +2366 -0
- package/dist/development/index-react-server-client.d.mts +3 -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 +109 -2
- package/dist/development/index-react-server.d.ts +109 -2
- package/dist/development/index-react-server.js +28 -20
- package/dist/development/index-react-server.mjs +29 -21
- package/dist/development/index.d.mts +918 -287
- package/dist/development/index.d.ts +1010 -283
- package/dist/development/index.js +98 -100
- package/dist/development/index.mjs +3 -3
- package/dist/development/lib/types/internal.d.mts +1 -1
- 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/{production/route-data-DjzmHYNR.d.mts → development/route-data-CqEmXQub.d.mts} +48 -2
- package/dist/{production/routeModules-g5PTiDfO.d.ts → development/routeModules-BR2FO0ix.d.ts} +48 -2
- package/dist/production/{browser-CcxeZJcQ.d.mts → browser-7LYX59NK.d.mts} +97 -1
- package/dist/{development/chunk-4ADB4KIO.js → production/chunk-4DGLNKXF.js} +132 -132
- package/dist/production/{chunk-5KHO4FML.js → chunk-7OQROU2D.js} +79 -76
- package/dist/production/{chunk-WPPIQDYG.mjs → chunk-IZ57JD2V.mjs} +83 -80
- package/dist/{development/chunk-T3VM44WY.mjs → production/chunk-K3SBCRK4.mjs} +3 -5
- package/dist/production/components-CjQijYga.d.mts +802 -0
- package/dist/production/dom-export.d.mts +13 -6
- package/dist/production/dom-export.d.ts +10 -3
- 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 +3163 -0
- package/dist/production/index-react-server-client-KLg-U4nr.d.mts +2366 -0
- package/dist/production/index-react-server-client.d.mts +3 -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 +109 -2
- package/dist/production/index-react-server.d.ts +109 -2
- package/dist/production/index-react-server.js +28 -20
- package/dist/production/index-react-server.mjs +29 -21
- package/dist/production/index.d.mts +918 -287
- package/dist/production/index.d.ts +1010 -283
- package/dist/production/index.js +98 -100
- package/dist/production/index.mjs +3 -3
- package/dist/production/lib/types/internal.d.mts +1 -1
- 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/{development/route-data-DjzmHYNR.d.mts → production/route-data-CqEmXQub.d.mts} +48 -2
- package/dist/{development/routeModules-g5PTiDfO.d.ts → production/routeModules-BR2FO0ix.d.ts} +48 -2
- package/package.json +1 -1
- package/dist/development/components-DzqPLVI1.d.mts +0 -464
- package/dist/development/index-react-server-client-CUidsuu_.d.mts +0 -1360
- package/dist/development/index-react-server-client-kY8DvDF3.d.ts +0 -1819
- package/dist/production/components-DzqPLVI1.d.mts +0 -464
- package/dist/production/index-react-server-client-CUidsuu_.d.mts +0 -1360
- package/dist/production/index-react-server-client-kY8DvDF3.d.ts +0 -1819
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { d as Router, e as RouteModules, D as DataStrategyFunction, T as To, f as NavigateOptions, B as BlockerFunction, g as Blocker, h as SerializeFrom, i as RelativeRoutingType, a as Location, j as ParamParseKey, k as Path, l as PathPattern, m as PathMatch, U as UIMatch, n as Navigation, A as Action, o as Params, p as RouteObject, I as InitialEntry, H as HydrationState, q as IndexRouteObject, r as LoaderFunction, s as ActionFunction, t as MetaFunction, v as LinksFunction, w as NonIndexRouteObject, x as AppLoadContext, y as unstable_RouterContextProvider, z as MiddlewareEnabled, E as unstable_InitialContext, F as Equal, J as ClientActionFunction, K as ClientLoaderFunction, O as HeadersFunction, Q as ShouldRevalidateFunction, V as RouterInit, W as RouterState, X as PatchRoutesOnNavigationFunction, Y as DataRouteObject } from './routeModules-
|
|
2
|
-
export { a7 as ActionFunctionArgs, aG as ClientActionFunctionArgs, aH as ClientLoaderFunctionArgs, aC as DataRouteMatch, a8 as DataStrategyFunctionArgs, a9 as DataStrategyMatch, aa as DataStrategyResult, ac as ErrorResponse, a1 as Fetcher, ad as FormEncType, ae as FormMethod, aM as Future, _ as GetScrollPositionFunction, $ as GetScrollRestorationKeyFunction, af as HTMLFormMethod, aI as HeadersArgs, aL as HtmlLinkDescriptor, as as IDLE_BLOCKER, ar as IDLE_FETCHER, aq as IDLE_NAVIGATION, ag as LazyRouteFunction, L as LinkDescriptor, ah as LoaderFunctionArgs, aJ as MetaArgs, M as MetaDescriptor, a2 as NavigationStates, aD as Navigator, aK as PageLinkDescriptor, aE as PatchRoutesOnNavigationFunctionArgs, aj as PathParam, ak as RedirectFunction, a6 as RevalidationState, aF as RouteMatch, a5 as RouterFetchOptions, a4 as RouterNavigateOptions, a3 as RouterSubscriber, am as ShouldRevalidateFunctionArgs, Z as StaticHandler, a0 as StaticHandlerContext, aS as UNSAFE_DataRouterContext, aT as UNSAFE_DataRouterStateContext, ab as UNSAFE_DataWithResponseInit, aR as UNSAFE_ErrorResponseImpl, aU as UNSAFE_FetchersContext, aV as UNSAFE_LocationContext, aW as UNSAFE_NavigationContext, aX as UNSAFE_RouteContext, aY as UNSAFE_ViewTransitionContext, aO as UNSAFE_createBrowserHistory, aQ as UNSAFE_createRouter, aP as UNSAFE_invariant, ao as createPath, at as data, au as generatePath, av as isRouteErrorResponse, aw as matchPath, ax as matchRoutes, ap as parsePath, ay as redirect, az as redirectDocument, aA as replace, aB as resolvePath, ai as unstable_MiddlewareFunction, al as unstable_RouterContext, aN as unstable_SerializesTo, an as unstable_createContext } from './routeModules-
|
|
3
|
-
import { A as AssetsManifest, E as EntryContext, F as FutureConfig, R as RouteComponentType, H as HydrateFallbackType, a as ErrorBoundaryType, S as ServerBuild } from './index-react-server-client-
|
|
4
|
-
export { h as Await, b as AwaitProps, V as BrowserRouter, B as BrowserRouterProps, D as DOMRouterOpts, y as FetcherFormProps, K as FetcherSubmitFunction, a9 as FetcherSubmitOptions, Q as FetcherWithComponents, _ as Form, z as FormProps,
|
|
1
|
+
import { d as Router, e as RouteModules, D as DataStrategyFunction, T as To, f as NavigateOptions, B as BlockerFunction, g as Blocker, h as SerializeFrom, i as RelativeRoutingType, a as Location, j as ParamParseKey, k as Path, l as PathPattern, m as PathMatch, U as UIMatch, n as Navigation, A as Action, o as Params, p as RouteObject, I as InitialEntry, H as HydrationState, q as IndexRouteObject, r as LoaderFunction, s as ActionFunction, t as MetaFunction, v as LinksFunction, w as NonIndexRouteObject, x as AppLoadContext, y as unstable_RouterContextProvider, z as MiddlewareEnabled, E as unstable_InitialContext, F as Equal, J as ClientActionFunction, K as ClientLoaderFunction, O as HeadersFunction, Q as ShouldRevalidateFunction, V as RouterInit, W as RouterState, X as PatchRoutesOnNavigationFunction, Y as DataRouteObject } from './routeModules-BR2FO0ix.js';
|
|
2
|
+
export { a7 as ActionFunctionArgs, aG as ClientActionFunctionArgs, aH as ClientLoaderFunctionArgs, aC as DataRouteMatch, a8 as DataStrategyFunctionArgs, a9 as DataStrategyMatch, aa as DataStrategyResult, ac as ErrorResponse, a1 as Fetcher, ad as FormEncType, ae as FormMethod, aM as Future, _ as GetScrollPositionFunction, $ as GetScrollRestorationKeyFunction, af as HTMLFormMethod, aI as HeadersArgs, aL as HtmlLinkDescriptor, as as IDLE_BLOCKER, ar as IDLE_FETCHER, aq as IDLE_NAVIGATION, ag as LazyRouteFunction, L as LinkDescriptor, ah as LoaderFunctionArgs, aJ as MetaArgs, M as MetaDescriptor, a2 as NavigationStates, aD as Navigator, aK as PageLinkDescriptor, aE as PatchRoutesOnNavigationFunctionArgs, aj as PathParam, ak as RedirectFunction, a6 as RevalidationState, aF as RouteMatch, a5 as RouterFetchOptions, a4 as RouterNavigateOptions, a3 as RouterSubscriber, am as ShouldRevalidateFunctionArgs, Z as StaticHandler, a0 as StaticHandlerContext, aS as UNSAFE_DataRouterContext, aT as UNSAFE_DataRouterStateContext, ab as UNSAFE_DataWithResponseInit, aR as UNSAFE_ErrorResponseImpl, aU as UNSAFE_FetchersContext, aV as UNSAFE_LocationContext, aW as UNSAFE_NavigationContext, aX as UNSAFE_RouteContext, aY as UNSAFE_ViewTransitionContext, aO as UNSAFE_createBrowserHistory, aQ as UNSAFE_createRouter, aP as UNSAFE_invariant, ao as createPath, at as data, au as generatePath, av as isRouteErrorResponse, aw as matchPath, ax as matchRoutes, ap as parsePath, ay as redirect, az as redirectDocument, aA as replace, aB as resolvePath, ai as unstable_MiddlewareFunction, al as unstable_RouterContext, aN as unstable_SerializesTo, an as unstable_createContext } from './routeModules-BR2FO0ix.js';
|
|
3
|
+
import { A as AssetsManifest, E as EntryContext, F as FutureConfig, R as RouteComponentType, H as HydrateFallbackType, a as ErrorBoundaryType, S as ServerBuild } from './index-react-server-client-Bi_fx8qz.js';
|
|
4
|
+
export { h as Await, b as AwaitProps, V as BrowserRouter, B as BrowserRouterProps, D as DOMRouterOpts, ar as DiscoverBehavior, y as FetcherFormProps, K as FetcherSubmitFunction, a9 as FetcherSubmitOptions, Q as FetcherWithComponents, _ as Form, z as FormProps, as as HandleDataRequestFunction, at as HandleDocumentRequestFunction, au as HandleErrorFunction, W as HashRouter, t as HashRouterProps, u as HistoryRouterProps, I as IndexRouteProps, L as LayoutRouteProps, X as Link, v as LinkProps, am as Links, i as MemoryRouter, M as MemoryRouterOpts, c as MemoryRouterProps, al as Meta, Z as NavLink, w as NavLinkProps, x as NavLinkRenderProps, j as Navigate, N as NavigateProps, k as Outlet, O as OutletProps, aa as ParamKeyValuePair, P as PathRouteProps, aq as PrefetchBehavior, ao as PrefetchPageLinks, l as Route, d as RouteProps, m as Router, e as RouterProps, n as RouterProvider, f as RouterProviderProps, o as Routes, g as RoutesProps, an as Scripts, ap as ScriptsProps, $ as ScrollRestoration, C as ScrollRestorationProps, av as ServerEntryModule, G as SetURLSearchParams, aj as StaticRouter, af as StaticRouterProps, ak as StaticRouterProvider, ag as StaticRouterProviderProps, J as SubmitFunction, ab as SubmitOptions, ad as SubmitTarget, aE as UNSAFE_FrameworkContext, ay as UNSAFE_WithComponentProps, aC as UNSAFE_WithErrorBoundaryProps, aA as UNSAFE_WithHydrateFallbackProps, aF as UNSAFE_createClientRoutes, aG as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, aw as UNSAFE_hydrationRouteProperties, ax as UNSAFE_mapRouteProperties, aH as UNSAFE_shouldHydrateRouteLoader, aI as UNSAFE_useScrollRestoration, az as UNSAFE_withComponentProps, aD as UNSAFE_withErrorBoundaryProps, aB as UNSAFE_withHydrateFallbackProps, ac as URLSearchParamsInit, T as createBrowserRouter, U as createHashRouter, p as createMemoryRouter, q as createRoutesFromChildren, r as createRoutesFromElements, ae as createSearchParams, ah as createStaticHandler, ai as createStaticRouter, s as renderMatches, Y as unstable_HistoryRouter, a7 as unstable_usePrompt, a6 as useBeforeUnload, a4 as useFetcher, a5 as useFetchers, a3 as useFormAction, a0 as useLinkClickHandler, a1 as useSearchParams, a2 as useSubmit, a8 as useViewTransitionState } from './index-react-server-client-Bi_fx8qz.js';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import React__default, { ReactElement } from 'react';
|
|
7
7
|
import { ParseOptions, SerializeOptions } from 'cookie';
|
|
@@ -27,369 +27,795 @@ declare enum ServerMode {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
* Resolves a URL against the current {@link Location}.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* import { useHref } from "react-router";
|
|
34
|
+
*
|
|
35
|
+
* function SomeComponent() {
|
|
36
|
+
* let href = useHref("some/where");
|
|
37
|
+
* // "/resolved/some/where"
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
* @category Hooks
|
|
42
|
+
* @param to The path to resolve
|
|
43
|
+
* @param options Options
|
|
44
|
+
* @param options.relative Defaults to `"route"` so routing is relative to the
|
|
45
|
+
* route tree.
|
|
46
|
+
* Set to `"path"` to make relative routing operate against path segments.
|
|
47
|
+
* @returns The resolved href string
|
|
42
48
|
*/
|
|
43
49
|
declare function useHref(to: To, { relative }?: {
|
|
44
50
|
relative?: RelativeRoutingType;
|
|
45
51
|
}): string;
|
|
46
52
|
/**
|
|
47
|
-
* Returns true if this component is a descendant of a Router, useful
|
|
48
|
-
* a component is used within a Router.
|
|
53
|
+
* Returns `true` if this component is a descendant of a {@link Router}, useful
|
|
54
|
+
* to ensure a component is used within a {@link Router}.
|
|
49
55
|
*
|
|
56
|
+
* @public
|
|
50
57
|
* @category Hooks
|
|
58
|
+
* @mode framework
|
|
59
|
+
* @mode data
|
|
60
|
+
* @returns Whether the component is within a {@link Router} context
|
|
51
61
|
*/
|
|
52
62
|
declare function useInRouterContext(): boolean;
|
|
53
63
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
* Returns the current {@link Location}. This can be useful if you'd like to
|
|
65
|
+
* perform some side effect whenever it changes.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* import * as React from 'react'
|
|
69
|
+
* import { useLocation } from 'react-router'
|
|
70
|
+
*
|
|
71
|
+
* function SomeComponent() {
|
|
72
|
+
* let location = useLocation()
|
|
73
|
+
*
|
|
74
|
+
* React.useEffect(() => {
|
|
75
|
+
* // Google Analytics
|
|
76
|
+
* ga('send', 'pageview')
|
|
77
|
+
* }, [location]);
|
|
78
|
+
*
|
|
79
|
+
* return (
|
|
80
|
+
* // ...
|
|
81
|
+
* );
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
* @category Hooks
|
|
86
|
+
* @returns The current {@link Location} object
|
|
75
87
|
*/
|
|
76
88
|
declare function useLocation(): Location;
|
|
77
89
|
/**
|
|
78
|
-
* Returns the current
|
|
79
|
-
* the current
|
|
90
|
+
* Returns the current {@link Navigation} action which describes how the router
|
|
91
|
+
* came to the current {@link Location}, either by a pop, push, or replace on
|
|
92
|
+
* the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History) stack.
|
|
80
93
|
*
|
|
94
|
+
* @public
|
|
81
95
|
* @category Hooks
|
|
96
|
+
* @returns The current {@link NavigationType} type (`"PUSH"`, `"REPLACE"`, or `"POP"`)
|
|
82
97
|
*/
|
|
83
98
|
declare function useNavigationType(): Action;
|
|
84
99
|
/**
|
|
85
|
-
* Returns a PathMatch object if the given pattern matches the current URL.
|
|
100
|
+
* Returns a {@link PathMatch} object if the given pattern matches the current URL.
|
|
86
101
|
* This is useful for components that need to know "active" state, e.g.
|
|
87
|
-
* `<NavLink
|
|
102
|
+
* {@link NavLink | `<NavLink>`}.
|
|
88
103
|
*
|
|
104
|
+
* @public
|
|
89
105
|
* @category Hooks
|
|
106
|
+
* @param pattern The pattern to match against the current {@link Location}
|
|
107
|
+
* @returns The path match object if the pattern matches, `null` otherwise
|
|
90
108
|
*/
|
|
91
109
|
declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
|
|
92
110
|
/**
|
|
93
|
-
* The interface for the navigate
|
|
111
|
+
* The interface for the `navigate` function returned from {@link useNavigate}.
|
|
94
112
|
*/
|
|
95
113
|
interface NavigateFunction {
|
|
96
114
|
(to: To, options?: NavigateOptions): void | Promise<void>;
|
|
97
115
|
(delta: number): void | Promise<void>;
|
|
98
116
|
}
|
|
99
117
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
* Returns a function that lets you navigate programmatically in the browser in
|
|
119
|
+
* response to user interactions or effects.
|
|
120
|
+
*
|
|
121
|
+
* It's often better to use {@link redirect} in [`action`](../../start/framework/route-module#action)/[`loader`](../../start/framework/route-module#loader)
|
|
122
|
+
* functions than this hook.
|
|
123
|
+
*
|
|
124
|
+
* The returned function signature is `navigate(to, options?)`/`navigate(delta)` where:
|
|
125
|
+
*
|
|
126
|
+
* * `to` can be a string path, a {@link To} object, or a number (delta)
|
|
127
|
+
* * `options` contains options for modifying the navigation
|
|
128
|
+
* * `flushSync`: Wrap the DOM updates in [`ReactDom.flushSync`](https://react.dev/reference/react-dom/flushSync)
|
|
129
|
+
* * `preventScrollReset`: Do not scroll back to the top of the page after navigation
|
|
130
|
+
* * `relative`: `"route"` or `"path"` to control relative routing logic
|
|
131
|
+
* * `replace`: Replace the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History) stack
|
|
132
|
+
* * `state`: Optional [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state) to include with the new {@link Location}
|
|
133
|
+
* * `viewTransition`: Enable [`document.startViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) for this navigation
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* import { useNavigate } from "react-router";
|
|
137
|
+
*
|
|
138
|
+
* function SomeComponent() {
|
|
139
|
+
* let navigate = useNavigate();
|
|
140
|
+
* return (
|
|
141
|
+
* <button onClick={() => navigate(-1)}>
|
|
142
|
+
* Go Back
|
|
143
|
+
* </button>
|
|
144
|
+
* );
|
|
145
|
+
* }
|
|
146
|
+
*
|
|
147
|
+
* @additionalExamples
|
|
148
|
+
* ### Navigate to another path
|
|
149
|
+
*
|
|
150
|
+
* ```tsx
|
|
151
|
+
* navigate("/some/route");
|
|
152
|
+
* navigate("/some/route?search=param");
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* ### Navigate with a {@link To} object
|
|
156
|
+
*
|
|
157
|
+
* All properties are optional.
|
|
158
|
+
*
|
|
159
|
+
* ```tsx
|
|
160
|
+
* navigate({
|
|
161
|
+
* pathname: "/some/route",
|
|
162
|
+
* search: "?search=param",
|
|
163
|
+
* hash: "#hash",
|
|
164
|
+
* state: { some: "state" },
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* If you use `state`, that will be available on the {@link Location} object on
|
|
169
|
+
* the next page. Access it with `useLocation().state` (see {@link useLocation}).
|
|
170
|
+
*
|
|
171
|
+
* ### Navigate back or forward in the history stack
|
|
172
|
+
*
|
|
173
|
+
* ```tsx
|
|
174
|
+
* // back
|
|
175
|
+
* // often used to close modals
|
|
176
|
+
* navigate(-1);
|
|
177
|
+
*
|
|
178
|
+
* // forward
|
|
179
|
+
* // often used in a multistep wizard workflows
|
|
180
|
+
* navigate(1);
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* Be cautious with `navigate(number)`. If your application can load up to a
|
|
184
|
+
* route that has a button that tries to navigate forward/back, there may not be
|
|
185
|
+
* a `[`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
|
186
|
+
* entry to go back or forward to, or it can go somewhere you don't expect
|
|
187
|
+
* (like a different domain).
|
|
188
|
+
*
|
|
189
|
+
* Only use this if you're sure they will have an entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
|
190
|
+
* stack to navigate to.
|
|
191
|
+
*
|
|
192
|
+
* ### Replace the current entry in the history stack
|
|
193
|
+
*
|
|
194
|
+
* This will remove the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
|
|
195
|
+
* stack, replacing it with a new one, similar to a server side redirect.
|
|
196
|
+
*
|
|
197
|
+
* ```tsx
|
|
198
|
+
* navigate("/some/route", { replace: true });
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* ### Prevent Scroll Reset
|
|
202
|
+
*
|
|
203
|
+
* [MODES: framework, data]
|
|
204
|
+
*
|
|
205
|
+
* <br/>
|
|
206
|
+
* <br/>
|
|
207
|
+
*
|
|
208
|
+
* To prevent {@link ScrollRestoration | `<ScrollRestoration>`} from resetting
|
|
209
|
+
* the scroll position, use the `preventScrollReset` option.
|
|
210
|
+
*
|
|
211
|
+
* ```tsx
|
|
212
|
+
* navigate("?some-tab=1", { preventScrollReset: true });
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* For example, if you have a tab interface connected to search params in the
|
|
216
|
+
* middle of a page, and you don't want it to scroll to the top when a tab is
|
|
217
|
+
* clicked.
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
* @category Hooks
|
|
221
|
+
* @returns A navigate function for programmatic navigation
|
|
120
222
|
*/
|
|
121
223
|
declare function useNavigate(): NavigateFunction;
|
|
122
224
|
/**
|
|
123
|
-
* Returns the parent route {@link
|
|
225
|
+
* Returns the parent route {@link Outlet | `<Outlet context>`}.
|
|
226
|
+
*
|
|
227
|
+
* Often parent routes manage state or other values you want shared with child
|
|
228
|
+
* routes. You can create your own [context provider](https://react.dev/learn/passing-data-deeply-with-context)
|
|
229
|
+
* if you like, but this is such a common situation that it's built-into
|
|
230
|
+
* `<Outlet />`.
|
|
231
|
+
*
|
|
232
|
+
* ```tsx
|
|
233
|
+
* // Parent route
|
|
234
|
+
* function Parent() {
|
|
235
|
+
* const [count, setCount] = React.useState(0);
|
|
236
|
+
* return <Outlet context={[count, setCount]} />;
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* ```tsx
|
|
241
|
+
* // Child route
|
|
242
|
+
* import { useOutletContext } from "react-router-dom";
|
|
243
|
+
*
|
|
244
|
+
* function Child() {
|
|
245
|
+
* const [count, setCount] = useOutletContext();
|
|
246
|
+
* const increment = () => setCount((c) => c + 1);
|
|
247
|
+
* return <button onClick={increment}>{count}</button>;
|
|
248
|
+
* }
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
251
|
+
* If you're using TypeScript, we recommend the parent component provide a custom
|
|
252
|
+
* hook for accessing the context value. This makes it easier for consumers to
|
|
253
|
+
* get nice typings, control consumers, and know who's consuming the context value.
|
|
254
|
+
*
|
|
255
|
+
* Here's a more realistic example:
|
|
124
256
|
*
|
|
257
|
+
* ```tsx filename=src/routes/dashboard.tsx lines=[13,19]
|
|
258
|
+
* import * as React from "react";
|
|
259
|
+
* import type { User } from "./types";
|
|
260
|
+
* import { Outlet, useOutletContext } from "react-router-dom";
|
|
261
|
+
*
|
|
262
|
+
* type ContextType = { user: User | null };
|
|
263
|
+
*
|
|
264
|
+
* export default function Dashboard() {
|
|
265
|
+
* const [user, setUser] = React.useState<User | null>(null);
|
|
266
|
+
*
|
|
267
|
+
* return (
|
|
268
|
+
* <div>
|
|
269
|
+
* <h1>Dashboard</h1>
|
|
270
|
+
* <Outlet context={{ user } satisfies ContextType} />
|
|
271
|
+
* </div>
|
|
272
|
+
* );
|
|
273
|
+
* }
|
|
274
|
+
*
|
|
275
|
+
* export function useUser() {
|
|
276
|
+
* return useOutletContext<ContextType>();
|
|
277
|
+
* }
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* ```tsx filename=src/routes/dashboard/messages.tsx lines=[1,4]
|
|
281
|
+
* import { useUser } from "../dashboard";
|
|
282
|
+
*
|
|
283
|
+
* export default function DashboardMessages() {
|
|
284
|
+
* const { user } = useUser();
|
|
285
|
+
* return (
|
|
286
|
+
* <div>
|
|
287
|
+
* <h2>Messages</h2>
|
|
288
|
+
* <p>Hello, {user.name}!</p>
|
|
289
|
+
* </div>
|
|
290
|
+
* );
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @public
|
|
125
295
|
* @category Hooks
|
|
296
|
+
* @returns The context value passed to the parent {@link Outlet} component
|
|
126
297
|
*/
|
|
127
298
|
declare function useOutletContext<Context = unknown>(): Context;
|
|
128
299
|
/**
|
|
129
300
|
* Returns the element for the child route at this level of the route
|
|
130
|
-
* hierarchy. Used internally by `<Outlet>` to render child
|
|
301
|
+
* hierarchy. Used internally by {@link Outlet | `<Outlet>`} to render child
|
|
302
|
+
* routes.
|
|
131
303
|
*
|
|
304
|
+
* @public
|
|
132
305
|
* @category Hooks
|
|
306
|
+
* @param context The context to pass to the outlet
|
|
307
|
+
* @returns The child route element or `null` if no child routes match
|
|
133
308
|
*/
|
|
134
309
|
declare function useOutlet(context?: unknown): React.ReactElement | null;
|
|
135
310
|
/**
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
311
|
+
* Returns an object of key/value-pairs of the dynamic params from the current
|
|
312
|
+
* URL that were matched by the routes. Child routes inherit all params from
|
|
313
|
+
* their parent routes.
|
|
314
|
+
*
|
|
315
|
+
* Assuming a route pattern like `/posts/:postId` is matched by `/posts/123`
|
|
316
|
+
* then `params.postId` will be `"123"`.
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* import { useParams } from "react-router";
|
|
320
|
+
*
|
|
321
|
+
* function SomeComponent() {
|
|
322
|
+
* let params = useParams();
|
|
323
|
+
* params.postId;
|
|
324
|
+
* }
|
|
325
|
+
*
|
|
326
|
+
* @additionalExamples
|
|
327
|
+
* ### Basic Usage
|
|
328
|
+
*
|
|
329
|
+
* ```tsx
|
|
330
|
+
* import { useParams } from "react-router";
|
|
331
|
+
*
|
|
332
|
+
* // given a route like:
|
|
333
|
+
* <Route path="/posts/:postId" element={<Post />} />;
|
|
334
|
+
*
|
|
335
|
+
* // or a data route like:
|
|
336
|
+
* createBrowserRouter([
|
|
337
|
+
* {
|
|
338
|
+
* path: "/posts/:postId",
|
|
339
|
+
* component: Post,
|
|
340
|
+
* },
|
|
341
|
+
* ]);
|
|
342
|
+
*
|
|
343
|
+
* // or in routes.ts
|
|
344
|
+
* route("/posts/:postId", "routes/post.tsx");
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* Access the params in a component:
|
|
348
|
+
*
|
|
349
|
+
* ```tsx
|
|
350
|
+
* import { useParams } from "react-router";
|
|
351
|
+
*
|
|
352
|
+
* export default function Post() {
|
|
353
|
+
* let params = useParams();
|
|
354
|
+
* return <h1>Post: {params.postId}</h1>;
|
|
355
|
+
* }
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* ### Multiple Params
|
|
359
|
+
*
|
|
360
|
+
* Patterns can have multiple params:
|
|
361
|
+
*
|
|
362
|
+
* ```tsx
|
|
363
|
+
* "/posts/:postId/comments/:commentId";
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* All will be available in the params object:
|
|
367
|
+
*
|
|
368
|
+
* ```tsx
|
|
369
|
+
* import { useParams } from "react-router";
|
|
370
|
+
*
|
|
371
|
+
* export default function Post() {
|
|
372
|
+
* let params = useParams();
|
|
373
|
+
* return (
|
|
374
|
+
* <h1>
|
|
375
|
+
* Post: {params.postId}, Comment: {params.commentId}
|
|
376
|
+
* </h1>
|
|
377
|
+
* );
|
|
378
|
+
* }
|
|
379
|
+
* ```
|
|
380
|
+
*
|
|
381
|
+
* ### Catchall Params
|
|
382
|
+
*
|
|
383
|
+
* Catchall params are defined with `*`:
|
|
384
|
+
*
|
|
385
|
+
* ```tsx
|
|
386
|
+
* "/files/*";
|
|
387
|
+
* ```
|
|
388
|
+
*
|
|
389
|
+
* The matched value will be available in the params object as follows:
|
|
390
|
+
*
|
|
391
|
+
* ```tsx
|
|
392
|
+
* import { useParams } from "react-router";
|
|
393
|
+
*
|
|
394
|
+
* export default function File() {
|
|
395
|
+
* let params = useParams();
|
|
396
|
+
* let catchall = params["*"];
|
|
397
|
+
* // ...
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* You can destructure the catchall param:
|
|
402
|
+
*
|
|
403
|
+
* ```tsx
|
|
404
|
+
* export default function File() {
|
|
405
|
+
* let { "*": catchall } = useParams();
|
|
406
|
+
* console.log(catchall);
|
|
407
|
+
* }
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* @public
|
|
411
|
+
* @category Hooks
|
|
412
|
+
* @returns An object containing the dynamic route parameters
|
|
150
413
|
*/
|
|
151
414
|
declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
|
|
152
415
|
ParamsOrKey
|
|
153
416
|
] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>>;
|
|
154
417
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
418
|
+
* Resolves the pathname of the given `to` value against the current
|
|
419
|
+
* {@link Location}. Similar to {@link useHref}, but returns a
|
|
420
|
+
* {@link Path} instead of a string.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* import { useResolvedPath } from "react-router";
|
|
424
|
+
*
|
|
425
|
+
* function SomeComponent() {
|
|
426
|
+
* // if the user is at /dashboard/profile
|
|
427
|
+
* let path = useResolvedPath("../accounts");
|
|
428
|
+
* path.pathname; // "/dashboard/accounts"
|
|
429
|
+
* path.search; // ""
|
|
430
|
+
* path.hash; // ""
|
|
431
|
+
* }
|
|
432
|
+
*
|
|
433
|
+
* @public
|
|
434
|
+
* @category Hooks
|
|
435
|
+
* @param to The path to resolve
|
|
436
|
+
* @param options Options
|
|
437
|
+
* @param options.relative Defaults to `"route"` so routing is relative to the route tree.
|
|
438
|
+
* Set to `"path"` to make relative routing operate against path segments.
|
|
439
|
+
* @returns The resolved {@link Path} object with `pathname`, `search`, and `hash`
|
|
170
440
|
*/
|
|
171
441
|
declare function useResolvedPath(to: To, { relative }?: {
|
|
172
442
|
relative?: RelativeRoutingType;
|
|
173
443
|
}): Path;
|
|
174
444
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
@category Hooks
|
|
445
|
+
* Hook version of {@link Routes | `<Routes>`} that uses objects instead of
|
|
446
|
+
* components. These objects have the same properties as the component props.
|
|
447
|
+
* The return value of `useRoutes` is either a valid React element you can use
|
|
448
|
+
* to render the route tree, or `null` if nothing matched.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* import { useRoutes } from "react-router";
|
|
452
|
+
*
|
|
453
|
+
* function App() {
|
|
454
|
+
* let element = useRoutes([
|
|
455
|
+
* {
|
|
456
|
+
* path: "/",
|
|
457
|
+
* element: <Dashboard />,
|
|
458
|
+
* children: [
|
|
459
|
+
* {
|
|
460
|
+
* path: "messages",
|
|
461
|
+
* element: <DashboardMessages />,
|
|
462
|
+
* },
|
|
463
|
+
* { path: "tasks", element: <DashboardTasks /> },
|
|
464
|
+
* ],
|
|
465
|
+
* },
|
|
466
|
+
* { path: "team", element: <AboutPage /> },
|
|
467
|
+
* ]);
|
|
468
|
+
*
|
|
469
|
+
* return element;
|
|
470
|
+
* }
|
|
471
|
+
*
|
|
472
|
+
* @public
|
|
473
|
+
* @category Hooks
|
|
474
|
+
* @param routes An array of {@link RouteObject}s that define the route hierarchy
|
|
475
|
+
* @param locationArg An optional {@link Location} object or pathname string to
|
|
476
|
+
* use instead of the current {@link Location}
|
|
477
|
+
* @returns A React element to render the matched route, or `null` if no routes matched
|
|
204
478
|
*/
|
|
205
479
|
declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
|
|
206
480
|
/**
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
481
|
+
* Returns the current {@link Navigation}, defaulting to an "idle" navigation
|
|
482
|
+
* when no navigation is in progress. You can use this to render pending UI
|
|
483
|
+
* (like a global spinner) or read [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
|
|
484
|
+
* from a form navigation.
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* import { useNavigation } from "react-router";
|
|
488
|
+
*
|
|
489
|
+
* function SomeComponent() {
|
|
490
|
+
* let navigation = useNavigation();
|
|
491
|
+
* navigation.state;
|
|
492
|
+
* navigation.formData;
|
|
493
|
+
* // etc.
|
|
494
|
+
* }
|
|
495
|
+
*
|
|
496
|
+
* @public
|
|
497
|
+
* @category Hooks
|
|
498
|
+
* @mode framework
|
|
499
|
+
* @mode data
|
|
500
|
+
* @returns The current {@link Navigation} object
|
|
221
501
|
*/
|
|
222
502
|
declare function useNavigation(): Navigation;
|
|
223
503
|
/**
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
504
|
+
* Revalidate the data on the page for reasons outside of normal data mutations
|
|
505
|
+
* like [`Window` focus](https://developer.mozilla.org/en-US/docs/Web/API/Window/focus_event)
|
|
506
|
+
* or polling on an interval.
|
|
507
|
+
*
|
|
508
|
+
* Note that page data is already revalidated automatically after actions.
|
|
509
|
+
* If you find yourself using this for normal CRUD operations on your data in
|
|
510
|
+
* response to user interactions, you're probably not taking advantage of the
|
|
511
|
+
* other APIs like {@link useFetcher}, {@link Form}, {@link useSubmit} that do
|
|
512
|
+
* this automatically.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* import { useRevalidator } from "react-router";
|
|
516
|
+
*
|
|
517
|
+
* function WindowFocusRevalidator() {
|
|
518
|
+
* const revalidator = useRevalidator();
|
|
519
|
+
*
|
|
520
|
+
* useFakeWindowFocus(() => {
|
|
521
|
+
* revalidator.revalidate();
|
|
522
|
+
* });
|
|
523
|
+
*
|
|
524
|
+
* return (
|
|
525
|
+
* <div hidden={revalidator.state === "idle"}>
|
|
526
|
+
* Revalidating...
|
|
527
|
+
* </div>
|
|
528
|
+
* );
|
|
529
|
+
* }
|
|
530
|
+
*
|
|
531
|
+
* @public
|
|
532
|
+
* @category Hooks
|
|
533
|
+
* @mode framework
|
|
534
|
+
* @mode data
|
|
535
|
+
* @returns An object with a `revalidate` function and the current revalidation
|
|
536
|
+
* `state`
|
|
247
537
|
*/
|
|
248
538
|
declare function useRevalidator(): {
|
|
249
539
|
revalidate: () => Promise<void>;
|
|
250
540
|
state: Router["state"]["revalidation"];
|
|
251
541
|
};
|
|
252
542
|
/**
|
|
253
|
-
* Returns the active route matches, useful for accessing loaderData for
|
|
254
|
-
* parent/child routes or the route
|
|
543
|
+
* Returns the active route matches, useful for accessing `loaderData` for
|
|
544
|
+
* parent/child routes or the route [`handle`](../../start/framework/route-module#handle)
|
|
545
|
+
* property
|
|
255
546
|
*
|
|
547
|
+
* @public
|
|
256
548
|
* @category Hooks
|
|
549
|
+
* @mode framework
|
|
550
|
+
* @mode data
|
|
551
|
+
* @returns An array of {@link UIMatch | UI matches} for the current route hierarchy
|
|
257
552
|
*/
|
|
258
553
|
declare function useMatches(): UIMatch[];
|
|
259
554
|
/**
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
555
|
+
* Returns the data from the closest route
|
|
556
|
+
* [`loader`](../../start/framework/route-module#loader) or
|
|
557
|
+
* [`clientLoader`](../../start/framework/route-module#clientloader).
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* import { useLoaderData } from "react-router";
|
|
561
|
+
*
|
|
562
|
+
* export async function loader() {
|
|
563
|
+
* return await fakeDb.invoices.findAll();
|
|
564
|
+
* }
|
|
565
|
+
*
|
|
566
|
+
* export default function Invoices() {
|
|
567
|
+
* let invoices = useLoaderData<typeof loader>();
|
|
568
|
+
* // ...
|
|
569
|
+
* }
|
|
570
|
+
*
|
|
571
|
+
* @public
|
|
572
|
+
* @category Hooks
|
|
573
|
+
* @mode framework
|
|
574
|
+
* @mode data
|
|
575
|
+
* @returns The data returned from the route's [`loader`](../../start/framework/route-module#loader) or [`clientLoader`](../../start/framework/route-module#clientloader) function
|
|
276
576
|
*/
|
|
277
577
|
declare function useLoaderData<T = any>(): SerializeFrom<T>;
|
|
278
578
|
/**
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
579
|
+
* Returns the [`loader`](../../start/framework/route-module#loader) data for a
|
|
580
|
+
* given route by route ID.
|
|
581
|
+
*
|
|
582
|
+
* Route IDs are created automatically. They are simply the path of the route file
|
|
583
|
+
* relative to the app folder without the extension.
|
|
584
|
+
*
|
|
585
|
+
* | Route Filename | Route ID |
|
|
586
|
+
* | ---------------------------- | ---------------------- |
|
|
587
|
+
* | `app/root.tsx` | `"root"` |
|
|
588
|
+
* | `app/routes/teams.tsx` | `"routes/teams"` |
|
|
589
|
+
* | `app/whatever/teams.$id.tsx` | `"whatever/teams.$id"` |
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* import { useRouteLoaderData } from "react-router";
|
|
593
|
+
*
|
|
594
|
+
* function SomeComponent() {
|
|
595
|
+
* const { user } = useRouteLoaderData("root");
|
|
596
|
+
* }
|
|
597
|
+
*
|
|
598
|
+
* // You can also specify your own route ID's manually in your routes.ts file:
|
|
599
|
+
* route("/", "containers/app.tsx", { id: "app" })
|
|
600
|
+
* useRouteLoaderData("app");
|
|
601
|
+
*
|
|
602
|
+
* @public
|
|
603
|
+
* @category Hooks
|
|
604
|
+
* @mode framework
|
|
605
|
+
* @mode data
|
|
606
|
+
* @param routeId The ID of the route to return loader data from
|
|
607
|
+
* @returns The data returned from the specified route's [`loader`](../../start/framework/route-module#loader)
|
|
608
|
+
* function, or `undefined` if not found
|
|
304
609
|
*/
|
|
305
610
|
declare function useRouteLoaderData<T = any>(routeId: string): SerializeFrom<T> | undefined;
|
|
306
611
|
/**
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
612
|
+
* Returns the [`action`](../../start/framework/route-module#action) data from
|
|
613
|
+
* the most recent `POST` navigation form submission or `undefined` if there
|
|
614
|
+
* hasn't been one.
|
|
615
|
+
*
|
|
616
|
+
* @example
|
|
617
|
+
* import { Form, useActionData } from "react-router";
|
|
618
|
+
*
|
|
619
|
+
* export async function action({ request }) {
|
|
620
|
+
* const body = await request.formData();
|
|
621
|
+
* const name = body.get("visitorsName");
|
|
622
|
+
* return { message: `Hello, ${name}` };
|
|
623
|
+
* }
|
|
624
|
+
*
|
|
625
|
+
* export default function Invoices() {
|
|
626
|
+
* const data = useActionData();
|
|
627
|
+
* return (
|
|
628
|
+
* <Form method="post">
|
|
629
|
+
* <input type="text" name="visitorsName" />
|
|
630
|
+
* {data ? data.message : "Waiting..."}
|
|
631
|
+
* </Form>
|
|
632
|
+
* );
|
|
633
|
+
* }
|
|
634
|
+
*
|
|
635
|
+
* @public
|
|
636
|
+
* @category Hooks
|
|
637
|
+
* @mode framework
|
|
638
|
+
* @mode data
|
|
639
|
+
* @returns The data returned from the route's [`action`](../../start/framework/route-module#action)
|
|
640
|
+
* function, or `undefined` if no [`action`](../../start/framework/route-module#action)
|
|
641
|
+
* has been called
|
|
330
642
|
*/
|
|
331
643
|
declare function useActionData<T = any>(): SerializeFrom<T> | undefined;
|
|
332
644
|
/**
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
645
|
+
* Accesses the error thrown during an
|
|
646
|
+
* [`action`](../../start/framework/route-module#action),
|
|
647
|
+
* [`loader`](../../start/framework/route-module#loader),
|
|
648
|
+
* or component render to be used in a route module
|
|
649
|
+
* [`ErrorBoundary`](../../start/framework/route-module#errorboundary).
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* export function ErrorBoundary() {
|
|
653
|
+
* const error = useRouteError();
|
|
654
|
+
* return <div>{error.message}</div>;
|
|
655
|
+
* }
|
|
656
|
+
*
|
|
657
|
+
* @public
|
|
658
|
+
* @category Hooks
|
|
659
|
+
* @mode framework
|
|
660
|
+
* @mode data
|
|
661
|
+
* @returns The error that was thrown during route [loading](../../start/framework/route-module#loader),
|
|
662
|
+
* [`action`](../../start/framework/route-module#action) execution, or rendering
|
|
343
663
|
*/
|
|
344
664
|
declare function useRouteError(): unknown;
|
|
345
665
|
/**
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
666
|
+
* Returns the resolved promise value from the closest {@link Await | `<Await>`}.
|
|
667
|
+
*
|
|
668
|
+
* @example
|
|
669
|
+
* function SomeDescendant() {
|
|
670
|
+
* const value = useAsyncValue();
|
|
671
|
+
* // ...
|
|
672
|
+
* }
|
|
673
|
+
*
|
|
674
|
+
* // somewhere in your app
|
|
675
|
+
* <Await resolve={somePromise}>
|
|
676
|
+
* <SomeDescendant />
|
|
677
|
+
* </Await>;
|
|
678
|
+
*
|
|
679
|
+
* @public
|
|
680
|
+
* @category Hooks
|
|
681
|
+
* @mode framework
|
|
682
|
+
* @mode data
|
|
683
|
+
* @returns The resolved value from the nearest {@link Await} component
|
|
361
684
|
*/
|
|
362
685
|
declare function useAsyncValue(): unknown;
|
|
363
686
|
/**
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
687
|
+
* Returns the rejection value from the closest {@link Await | `<Await>`}.
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* import { Await, useAsyncError } from "react-router";
|
|
691
|
+
*
|
|
692
|
+
* function ErrorElement() {
|
|
693
|
+
* const error = useAsyncError();
|
|
694
|
+
* return (
|
|
695
|
+
* <p>Uh Oh, something went wrong! {error.message}</p>
|
|
696
|
+
* );
|
|
697
|
+
* }
|
|
698
|
+
*
|
|
699
|
+
* // somewhere in your app
|
|
700
|
+
* <Await
|
|
701
|
+
* resolve={promiseThatRejects}
|
|
702
|
+
* errorElement={<ErrorElement />}
|
|
703
|
+
* />;
|
|
704
|
+
*
|
|
705
|
+
* @public
|
|
706
|
+
* @category Hooks
|
|
707
|
+
* @mode framework
|
|
708
|
+
* @mode data
|
|
709
|
+
* @returns The error that was thrown in the nearest {@link Await} component
|
|
384
710
|
*/
|
|
385
711
|
declare function useAsyncError(): unknown;
|
|
386
712
|
/**
|
|
387
713
|
* Allow the application to block navigations within the SPA and present the
|
|
388
|
-
* user a confirmation dialog to confirm the navigation.
|
|
389
|
-
* using half-filled form data.
|
|
714
|
+
* user a confirmation dialog to confirm the navigation. Mostly used to avoid
|
|
715
|
+
* using half-filled form data. This does not handle hard-reloads or
|
|
390
716
|
* cross-origin navigations.
|
|
391
717
|
*
|
|
718
|
+
* The {@link Blocker} object returned by the hook has the following properties:
|
|
719
|
+
*
|
|
720
|
+
* - **`state`**
|
|
721
|
+
* - `unblocked` - the blocker is idle and has not prevented any navigation
|
|
722
|
+
* - `blocked` - the blocker has prevented a navigation
|
|
723
|
+
* - `proceeding` - the blocker is proceeding through from a blocked navigation
|
|
724
|
+
* - **`location`**
|
|
725
|
+
* - When in a `blocked` state, this represents the {@link Location} to which we
|
|
726
|
+
* blocked a navigation. When in a `proceeding` state, this is the location
|
|
727
|
+
* being navigated to after a `blocker.proceed()` call.
|
|
728
|
+
* - **`proceed()`**
|
|
729
|
+
* - When in a `blocked` state, you may call `blocker.proceed()` to proceed to the
|
|
730
|
+
* blocked location.
|
|
731
|
+
* - **`reset()`**
|
|
732
|
+
* - When in a `blocked` state, you may call `blocker.reset()` to return the blocker
|
|
733
|
+
* back to an `unblocked` state and leave the user at the current location.
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* // Boolean version
|
|
737
|
+
* const blocker = useBlocker(value !== "");
|
|
738
|
+
*
|
|
739
|
+
* // Function version
|
|
740
|
+
* const blocker = useBlocker(
|
|
741
|
+
* ({ currentLocation, nextLocation, historyAction }) =>
|
|
742
|
+
* value !== "" &&
|
|
743
|
+
* currentLocation.pathname !== nextLocation.pathname
|
|
744
|
+
* );
|
|
745
|
+
*
|
|
746
|
+
* @additionalExamples
|
|
747
|
+
* ```tsx
|
|
748
|
+
* import { useCallback, useState } from "react";
|
|
749
|
+
* import { BlockerFunction, useBlocker } from "react-router";
|
|
750
|
+
*
|
|
751
|
+
* export function ImportantForm() {
|
|
752
|
+
* const [value, setValue] = useState("");
|
|
753
|
+
*
|
|
754
|
+
* const shouldBlock = useCallback<BlockerFunction>(
|
|
755
|
+
* () => value !== "",
|
|
756
|
+
* [value]
|
|
757
|
+
* );
|
|
758
|
+
* const blocker = useBlocker(shouldBlock);
|
|
759
|
+
*
|
|
760
|
+
* return (
|
|
761
|
+
* <form
|
|
762
|
+
* onSubmit={(e) => {
|
|
763
|
+
* e.preventDefault();
|
|
764
|
+
* setValue("");
|
|
765
|
+
* if (blocker.state === "blocked") {
|
|
766
|
+
* blocker.proceed();
|
|
767
|
+
* }
|
|
768
|
+
* }}
|
|
769
|
+
* >
|
|
770
|
+
* <input
|
|
771
|
+
* name="data"
|
|
772
|
+
* value={value}
|
|
773
|
+
* onChange={(e) => setValue(e.target.value)}
|
|
774
|
+
* />
|
|
775
|
+
*
|
|
776
|
+
* <button type="submit">Save</button>
|
|
777
|
+
*
|
|
778
|
+
* {blocker.state === "blocked" ? (
|
|
779
|
+
* <>
|
|
780
|
+
* <p style={{ color: "red" }}>
|
|
781
|
+
* Blocked the last navigation to
|
|
782
|
+
* </p>
|
|
783
|
+
* <button
|
|
784
|
+
* type="button"
|
|
785
|
+
* onClick={() => blocker.proceed()}
|
|
786
|
+
* >
|
|
787
|
+
* Let me through
|
|
788
|
+
* </button>
|
|
789
|
+
* <button
|
|
790
|
+
* type="button"
|
|
791
|
+
* onClick={() => blocker.reset()}
|
|
792
|
+
* >
|
|
793
|
+
* Keep me here
|
|
794
|
+
* </button>
|
|
795
|
+
* </>
|
|
796
|
+
* ) : blocker.state === "proceeding" ? (
|
|
797
|
+
* <p style={{ color: "orange" }}>
|
|
798
|
+
* Proceeding through blocked navigation
|
|
799
|
+
* </p>
|
|
800
|
+
* ) : (
|
|
801
|
+
* <p style={{ color: "green" }}>
|
|
802
|
+
* Blocker is currently unblocked
|
|
803
|
+
* </p>
|
|
804
|
+
* )}
|
|
805
|
+
* </form>
|
|
806
|
+
* );
|
|
807
|
+
* }
|
|
808
|
+
* ```
|
|
809
|
+
*
|
|
810
|
+
* @public
|
|
392
811
|
* @category Hooks
|
|
812
|
+
* @mode framework
|
|
813
|
+
* @mode data
|
|
814
|
+
* @param shouldBlock Either a boolean or a function returning a boolean which
|
|
815
|
+
* indicates whether the navigation should be blocked. The function format
|
|
816
|
+
* receives a single object parameter containing the `currentLocation`,
|
|
817
|
+
* `nextLocation`, and `historyAction` of the potential navigation.
|
|
818
|
+
* @returns A {@link Blocker} object with state and reset functionality
|
|
393
819
|
*/
|
|
394
820
|
declare function useBlocker(shouldBlock: boolean | BlockerFunction): Blocker;
|
|
395
821
|
|
|
@@ -399,11 +825,20 @@ interface ServerRouterProps {
|
|
|
399
825
|
nonce?: string;
|
|
400
826
|
}
|
|
401
827
|
/**
|
|
402
|
-
* The entry point for a
|
|
403
|
-
*
|
|
404
|
-
*
|
|
828
|
+
* The server entry point for a React Router app in Framework Mode. This component
|
|
829
|
+
* is used to generate the HTML in the response from the server.
|
|
830
|
+
* See [`entry.server.tsx`](../api/framework-conventions/entry.server.tsx).
|
|
405
831
|
*
|
|
406
|
-
* @
|
|
832
|
+
* @public
|
|
833
|
+
* @category Framework Routers
|
|
834
|
+
* @mode framework
|
|
835
|
+
* @param props Props
|
|
836
|
+
* @param props.context The entry context containing the manifest, route modules,
|
|
837
|
+
* and other data needed for rendering.
|
|
838
|
+
* @param props.url The URL of the request being handled.
|
|
839
|
+
* @param props.nonce An optional nonce for Content Security Policy (CSP) compliance,
|
|
840
|
+
* used to allow inline scripts to run safely.
|
|
841
|
+
* @returns A React element that represents the server-rendered application.
|
|
407
842
|
*/
|
|
408
843
|
declare function ServerRouter({ context, url, nonce, }: ServerRouterProps): ReactElement;
|
|
409
844
|
|
|
@@ -816,6 +1251,67 @@ type DecodeReplyFunction = (reply: FormData | string, { temporaryReferences }: {
|
|
|
816
1251
|
temporaryReferences: unknown;
|
|
817
1252
|
}) => Promise<unknown[]>;
|
|
818
1253
|
type LoadServerActionFunction = (id: string) => Promise<Function>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Matches the given routes to a Request and returns a RSC Response encoding an
|
|
1256
|
+
* `RSCPayload` for consumption by a RSC enabled client router.
|
|
1257
|
+
*
|
|
1258
|
+
* @example
|
|
1259
|
+
* import {
|
|
1260
|
+
* createTemporaryReferenceSet,
|
|
1261
|
+
* decodeAction,
|
|
1262
|
+
* decodeReply,
|
|
1263
|
+
* loadServerAction,
|
|
1264
|
+
* renderToReadableStream,
|
|
1265
|
+
* } from "@vitejs/plugin-rsc/rsc";
|
|
1266
|
+
* import { unstable_matchRSCServerRequest as matchRSCServerRequest } from "react-router";
|
|
1267
|
+
*
|
|
1268
|
+
* matchRSCServerRequest({
|
|
1269
|
+
* createTemporaryReferenceSet,
|
|
1270
|
+
* decodeAction,
|
|
1271
|
+
* decodeFormState,
|
|
1272
|
+
* decodeReply,
|
|
1273
|
+
* loadServerAction,
|
|
1274
|
+
* request,
|
|
1275
|
+
* routes: routes(),
|
|
1276
|
+
* generateResponse(match) {
|
|
1277
|
+
* return new Response(
|
|
1278
|
+
* renderToReadableStream(match.payload),
|
|
1279
|
+
* {
|
|
1280
|
+
* status: match.statusCode,
|
|
1281
|
+
* headers: match.headers,
|
|
1282
|
+
* }
|
|
1283
|
+
* );
|
|
1284
|
+
* },
|
|
1285
|
+
* });
|
|
1286
|
+
*
|
|
1287
|
+
* @name unstable_matchRSCServerRequest
|
|
1288
|
+
* @public
|
|
1289
|
+
* @category RSC
|
|
1290
|
+
* @mode data
|
|
1291
|
+
* @param opts Options
|
|
1292
|
+
* @param opts.basename The basename to use when matching the request.
|
|
1293
|
+
* @param opts.decodeAction Your `react-server-dom-xyz/server`'s `decodeAction`
|
|
1294
|
+
* function, responsible for loading a server action.
|
|
1295
|
+
* @param opts.decodeReply Your `react-server-dom-xyz/server`'s `decodeReply`
|
|
1296
|
+
* function, used to decode the server function's arguments and bind them to the
|
|
1297
|
+
* implementation for invocation by the router.
|
|
1298
|
+
* @param opts.decodeFormState A function responsible for decoding form state for
|
|
1299
|
+
* progressively enhanceable forms with `useActionState` using your
|
|
1300
|
+
* `react-server-dom-xyz/server`'s `decodeFormState`.
|
|
1301
|
+
* @param opts.generateResponse A function responsible for using your
|
|
1302
|
+
* `renderToReadableStream` to generate a Response encoding the `RSCPayload`.
|
|
1303
|
+
* @param opts.loadServerAction Your `react-server-dom-xyz/server`'s
|
|
1304
|
+
* `loadServerAction` function, used to load a server action by ID.
|
|
1305
|
+
* @param opts.request The request to match against.
|
|
1306
|
+
* @param opts.requestContext An instance of `unstable_RouterContextProvider`
|
|
1307
|
+
* that should be created per request, to be passed to loaders, actions and middleware.
|
|
1308
|
+
* @param opts.routes Your route definitions.
|
|
1309
|
+
* @param opts.createTemporaryReferenceSet A function that returns a temporary
|
|
1310
|
+
* reference set for the request, used to track temporary references in the RSC stream.
|
|
1311
|
+
* @param opts.onError An optional error handler that will be called with any
|
|
1312
|
+
* errors that occur during the request processing.
|
|
1313
|
+
* @returns A Response that contains the RSC data for hydration.
|
|
1314
|
+
*/
|
|
819
1315
|
declare function matchRSCServerRequest({ createTemporaryReferenceSet, basename, decodeReply, requestContext, loadServerAction, decodeAction, decodeFormState, onError, request, routes, generateResponse, }: {
|
|
820
1316
|
createTemporaryReferenceSet: () => unknown;
|
|
821
1317
|
basename?: string;
|
|
@@ -838,21 +1334,171 @@ type BrowserCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>
|
|
|
838
1334
|
type EncodeReplyFunction = (args: unknown[], options: {
|
|
839
1335
|
temporaryReferences: unknown;
|
|
840
1336
|
}) => Promise<BodyInit>;
|
|
1337
|
+
/**
|
|
1338
|
+
* Create a React `callServer` implementation for React Router.
|
|
1339
|
+
*
|
|
1340
|
+
* @example
|
|
1341
|
+
* import {
|
|
1342
|
+
* createFromReadableStream,
|
|
1343
|
+
* createTemporaryReferenceSet,
|
|
1344
|
+
* encodeReply,
|
|
1345
|
+
* setServerCallback,
|
|
1346
|
+
* } from "@vitejs/plugin-rsc/browser";
|
|
1347
|
+
* import { unstable_createCallServer as createCallServer } from "react-router";
|
|
1348
|
+
*
|
|
1349
|
+
* setServerCallback(
|
|
1350
|
+
* createCallServer({
|
|
1351
|
+
* createFromReadableStream,
|
|
1352
|
+
* createTemporaryReferenceSet,
|
|
1353
|
+
* encodeReply,
|
|
1354
|
+
* })
|
|
1355
|
+
* );
|
|
1356
|
+
*
|
|
1357
|
+
* @name unstable_createCallServer
|
|
1358
|
+
* @public
|
|
1359
|
+
* @category RSC
|
|
1360
|
+
* @mode data
|
|
1361
|
+
* @param opts Options
|
|
1362
|
+
* @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
|
|
1363
|
+
* `createFromReadableStream`. Used to decode payloads from the server.
|
|
1364
|
+
* @param opts.createTemporaryReferenceSet A function that creates a temporary
|
|
1365
|
+
* reference set for the RSC payload.
|
|
1366
|
+
* @param opts.encodeReply Your `react-server-dom-xyz/client`'s `encodeReply`.
|
|
1367
|
+
* Used when sending payloads to the server.
|
|
1368
|
+
* @param opts.fetch Optional fetch implementation. Defaults to global `fetch`.
|
|
1369
|
+
* @returns A function that can be used to call server actions.
|
|
1370
|
+
*/
|
|
841
1371
|
declare function createCallServer({ createFromReadableStream, createTemporaryReferenceSet, encodeReply, fetch: fetchImplementation, }: {
|
|
842
1372
|
createFromReadableStream: BrowserCreateFromReadableStreamFunction;
|
|
843
1373
|
createTemporaryReferenceSet: () => unknown;
|
|
844
1374
|
encodeReply: EncodeReplyFunction;
|
|
845
1375
|
fetch?: (request: Request) => Promise<Response>;
|
|
846
1376
|
}): (id: string, args: unknown[]) => Promise<unknown>;
|
|
847
|
-
|
|
1377
|
+
/**
|
|
1378
|
+
* Props for the `unstable_RSCHydratedRouter` component.
|
|
1379
|
+
* @name unstable_RSCHydratedRouterProps
|
|
1380
|
+
*/
|
|
1381
|
+
interface RSCHydratedRouterProps {
|
|
1382
|
+
/**
|
|
1383
|
+
* Your `react-server-dom-xyz/client`'s `createFromReadableStream` function,
|
|
1384
|
+
* used to decode payloads from the server.
|
|
1385
|
+
*/
|
|
848
1386
|
createFromReadableStream: BrowserCreateFromReadableStreamFunction;
|
|
1387
|
+
/**
|
|
1388
|
+
* Optional fetch implementation. Defaults to global `fetch`.
|
|
1389
|
+
*/
|
|
849
1390
|
fetch?: (request: Request) => Promise<Response>;
|
|
1391
|
+
/**
|
|
1392
|
+
* The decoded `RSCPayload` to hydrate.
|
|
1393
|
+
*/
|
|
850
1394
|
payload: RSCPayload;
|
|
1395
|
+
/**
|
|
1396
|
+
* `eager` or `lazy` - Determines if links are eagerly discovered, or delayed
|
|
1397
|
+
* until clicked.
|
|
1398
|
+
*/
|
|
851
1399
|
routeDiscovery?: "eager" | "lazy";
|
|
1400
|
+
/**
|
|
1401
|
+
* A function that returns an `unstable_InitialContext` object
|
|
1402
|
+
* (`Map<RouterContext, unknown>`), for use in client loaders, actions and
|
|
1403
|
+
* middleware.
|
|
1404
|
+
*/
|
|
852
1405
|
unstable_getContext?: RouterInit["unstable_getContext"];
|
|
853
|
-
}
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Hydrates a server rendered `RSCPayload` in the browser.
|
|
1409
|
+
*
|
|
1410
|
+
* @example
|
|
1411
|
+
* import { startTransition, StrictMode } from "react";
|
|
1412
|
+
* import { hydrateRoot } from "react-dom/client";
|
|
1413
|
+
* import {
|
|
1414
|
+
* unstable_getRSCStream as getRSCStream,
|
|
1415
|
+
* unstable_RSCHydratedRouter as RSCHydratedRouter,
|
|
1416
|
+
* } from "react-router";
|
|
1417
|
+
* import type { unstable_RSCPayload as RSCPayload } from "react-router";
|
|
1418
|
+
*
|
|
1419
|
+
* createFromReadableStream(getRSCStream()).then(
|
|
1420
|
+
* (payload: RSCServerPayload) => {
|
|
1421
|
+
* startTransition(async () => {
|
|
1422
|
+
* hydrateRoot(
|
|
1423
|
+
* document,
|
|
1424
|
+
* <StrictMode>
|
|
1425
|
+
* <RSCHydratedRouter
|
|
1426
|
+
* createFromReadableStream={
|
|
1427
|
+
* createFromReadableStream
|
|
1428
|
+
* }
|
|
1429
|
+
* payload={payload}
|
|
1430
|
+
* />
|
|
1431
|
+
* </StrictMode>,
|
|
1432
|
+
* {
|
|
1433
|
+
* formState: await getFormState(payload),
|
|
1434
|
+
* }
|
|
1435
|
+
* );
|
|
1436
|
+
* });
|
|
1437
|
+
* }
|
|
1438
|
+
* );
|
|
1439
|
+
*
|
|
1440
|
+
* @name unstable_RSCHydratedRouter
|
|
1441
|
+
* @public
|
|
1442
|
+
* @category RSC
|
|
1443
|
+
* @mode data
|
|
1444
|
+
* @param props Props
|
|
1445
|
+
* @param {unstable_RSCHydratedRouterProps.createFromReadableStream} props.createFromReadableStream n/a
|
|
1446
|
+
* @param {unstable_RSCHydratedRouterProps.fetch} props.fetch n/a
|
|
1447
|
+
* @param {unstable_RSCHydratedRouterProps.payload} props.payload n/a
|
|
1448
|
+
* @param {unstable_RSCHydratedRouterProps.routeDiscovery} props.routeDiscovery n/a
|
|
1449
|
+
* @param {unstable_RSCHydratedRouterProps.unstable_getContext} props.unstable_getContext n/a
|
|
1450
|
+
* @returns A hydrated router that can be used to navigate and render routes.
|
|
1451
|
+
*/
|
|
1452
|
+
declare function RSCHydratedRouter({ createFromReadableStream, fetch: fetchImplementation, payload, routeDiscovery, unstable_getContext, }: RSCHydratedRouterProps): React.JSX.Element;
|
|
854
1453
|
|
|
855
1454
|
type SSRCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
1455
|
+
/**
|
|
1456
|
+
* Routes the incoming request to the RSC server and appropriately proxies the
|
|
1457
|
+
* server response for data / resource requests, or renders to HTML for a document
|
|
1458
|
+
* request.
|
|
1459
|
+
*
|
|
1460
|
+
* @example
|
|
1461
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
1462
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
1463
|
+
* import {
|
|
1464
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
1465
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
1466
|
+
* } from "react-router";
|
|
1467
|
+
*
|
|
1468
|
+
* routeRSCServerRequest({
|
|
1469
|
+
* request,
|
|
1470
|
+
* fetchServer,
|
|
1471
|
+
* createFromReadableStream,
|
|
1472
|
+
* async renderHTML(getPayload) {
|
|
1473
|
+
* const payload = await getPayload();
|
|
1474
|
+
*
|
|
1475
|
+
* return await renderHTMLToReadableStream(
|
|
1476
|
+
* <RSCStaticRouter getPayload={getPayload} />,
|
|
1477
|
+
* {
|
|
1478
|
+
* bootstrapScriptContent,
|
|
1479
|
+
* formState: await getFormState(payload),
|
|
1480
|
+
* }
|
|
1481
|
+
* );
|
|
1482
|
+
* },
|
|
1483
|
+
* });
|
|
1484
|
+
*
|
|
1485
|
+
* @name unstable_routeRSCServerRequest
|
|
1486
|
+
* @public
|
|
1487
|
+
* @category RSC
|
|
1488
|
+
* @mode data
|
|
1489
|
+
* @param opts Options
|
|
1490
|
+
* @param opts.createFromReadableStream Your `react-server-dom-xyz/client`'s
|
|
1491
|
+
* `createFromReadableStream` function, used to decode payloads from the server.
|
|
1492
|
+
* @param opts.fetchServer A function that forwards a `Request` to the RSC handler
|
|
1493
|
+
* and returns a `Promise<Response>` containing a serialized `RSCPayload`.
|
|
1494
|
+
* @param opts.renderHTML A function that renders the `RSCPayload` to HTML, usually
|
|
1495
|
+
* using a `<RSCStaticRouter>`.
|
|
1496
|
+
* @param opts.request The request to route.
|
|
1497
|
+
* @param opts.hydrate Whether to hydrate the server response with the RSC payload.
|
|
1498
|
+
* Defaults to `true`.
|
|
1499
|
+
* @returns A `Response` that either contains the RSC payload for data requests, or
|
|
1500
|
+
* renders the HTML for document requests.
|
|
1501
|
+
*/
|
|
856
1502
|
declare function routeRSCServerRequest({ request, fetchServer, createFromReadableStream, renderHTML, hydrate, }: {
|
|
857
1503
|
request: Request;
|
|
858
1504
|
fetchServer: (request: Request) => Promise<Response>;
|
|
@@ -860,15 +1506,96 @@ declare function routeRSCServerRequest({ request, fetchServer, createFromReadabl
|
|
|
860
1506
|
renderHTML: (getPayload: () => Promise<RSCPayload>) => ReadableStream<Uint8Array> | Promise<ReadableStream<Uint8Array>>;
|
|
861
1507
|
hydrate?: boolean;
|
|
862
1508
|
}): Promise<Response>;
|
|
863
|
-
|
|
1509
|
+
/**
|
|
1510
|
+
* Props for the `RSCStaticRouter` component.
|
|
1511
|
+
* @name unstable_RSCStaticRouterProps
|
|
1512
|
+
*/
|
|
1513
|
+
interface RSCStaticRouterProps {
|
|
1514
|
+
/**
|
|
1515
|
+
* A function that starts decoding of the `RSCPayload`. Usually passed through
|
|
1516
|
+
* from `routeRSCServerRequest`'s `renderHTML`.
|
|
1517
|
+
*/
|
|
864
1518
|
getPayload: () => Promise<RSCPayload>;
|
|
865
|
-
}
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Pre-renders an `RSCPayload` to HTML. Usually used in `routeRSCServerRequest`'s
|
|
1522
|
+
* `renderHTML` callback.
|
|
1523
|
+
*
|
|
1524
|
+
* @example
|
|
1525
|
+
* import { createFromReadableStream } from "@vitejs/plugin-rsc/ssr";
|
|
1526
|
+
* import * as ReactDomServer from "react-dom/server.edge";
|
|
1527
|
+
* import {
|
|
1528
|
+
* unstable_RSCStaticRouter as RSCStaticRouter,
|
|
1529
|
+
* unstable_routeRSCServerRequest as routeRSCServerRequest,
|
|
1530
|
+
* } from "react-router";
|
|
1531
|
+
*
|
|
1532
|
+
* routeRSCServerRequest({
|
|
1533
|
+
* request,
|
|
1534
|
+
* fetchServer,
|
|
1535
|
+
* createFromReadableStream,
|
|
1536
|
+
* async renderHTML(getPayload) {
|
|
1537
|
+
* const payload = await getPayload();
|
|
1538
|
+
*
|
|
1539
|
+
* return await renderHTMLToReadableStream(
|
|
1540
|
+
* <RSCStaticRouter getPayload={getPayload} />,
|
|
1541
|
+
* {
|
|
1542
|
+
* bootstrapScriptContent,
|
|
1543
|
+
* formState: await getFormState(payload),
|
|
1544
|
+
* }
|
|
1545
|
+
* );
|
|
1546
|
+
* },
|
|
1547
|
+
* });
|
|
1548
|
+
*
|
|
1549
|
+
* @name unstable_RSCStaticRouter
|
|
1550
|
+
* @public
|
|
1551
|
+
* @category RSC
|
|
1552
|
+
* @mode data
|
|
1553
|
+
* @param props Props
|
|
1554
|
+
* @param {unstable_RSCStaticRouterProps.getPayload} props.getPayload n/a
|
|
1555
|
+
* @returns A React component that renders the `RSCPayload` as HTML.
|
|
1556
|
+
*/
|
|
1557
|
+
declare function RSCStaticRouter({ getPayload }: RSCStaticRouterProps): React.JSX.Element | null;
|
|
866
1558
|
|
|
867
1559
|
declare global {
|
|
868
1560
|
interface Window {
|
|
869
1561
|
__FLIGHT_DATA: any[];
|
|
870
1562
|
}
|
|
871
1563
|
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Get the prerendered RSC stream for hydration. Usually passed directly to your
|
|
1566
|
+
* `react-server-dom-xyz/client`'s `createFromReadableStream`.
|
|
1567
|
+
*
|
|
1568
|
+
* @example
|
|
1569
|
+
* import { startTransition, StrictMode } from "react";
|
|
1570
|
+
* import { hydrateRoot } from "react-dom/client";
|
|
1571
|
+
* import {
|
|
1572
|
+
* unstable_getRSCStream as getRSCStream,
|
|
1573
|
+
* unstable_RSCHydratedRouter as RSCHydratedRouter,
|
|
1574
|
+
* } from "react-router";
|
|
1575
|
+
* import type { unstable_RSCPayload as RSCPayload } from "react-router";
|
|
1576
|
+
*
|
|
1577
|
+
* createFromReadableStream(getRSCStream()).then(
|
|
1578
|
+
* (payload: RSCServerPayload) => {
|
|
1579
|
+
* startTransition(async () => {
|
|
1580
|
+
* hydrateRoot(
|
|
1581
|
+
* document,
|
|
1582
|
+
* <StrictMode>
|
|
1583
|
+
* <RSCHydratedRouter ...props />
|
|
1584
|
+
* </StrictMode>,
|
|
1585
|
+
* {
|
|
1586
|
+
* // Options
|
|
1587
|
+
* }
|
|
1588
|
+
* );
|
|
1589
|
+
* });
|
|
1590
|
+
* }
|
|
1591
|
+
* );
|
|
1592
|
+
*
|
|
1593
|
+
* @name unstable_getRSCStream
|
|
1594
|
+
* @public
|
|
1595
|
+
* @category RSC
|
|
1596
|
+
* @mode data
|
|
1597
|
+
* @returns A `ReadableStream` that contains the RSC data for hydration.
|
|
1598
|
+
*/
|
|
872
1599
|
declare function getRSCStream(): ReadableStream<any>;
|
|
873
1600
|
|
|
874
1601
|
declare function RSCDefaultRootErrorBoundary({ hasRootLayout, }: {
|
|
@@ -913,4 +1640,4 @@ declare function getHydrationData(state: {
|
|
|
913
1640
|
|
|
914
1641
|
declare const unstable_matchRSCServerRequest: typeof matchRSCServerRequest;
|
|
915
1642
|
|
|
916
|
-
export { ActionFunction, AppLoadContext, Blocker, BlockerFunction, ClientActionFunction, ClientLoaderFunction, type Cookie, type CookieOptions, type CookieSignatureOptions, type CreateRequestHandlerFunction, DataRouteObject, Router as DataRouter, DataStrategyFunction, EntryContext, type FlashSessionData, HeadersFunction, HydrationState, IndexRouteObject, InitialEntry, type IsCookieFunction, type IsSessionFunction, LinksFunction, LoaderFunction, Location, MetaFunction, type NavigateFunction, NavigateOptions, Navigation, Action as NavigationType, NonIndexRouteObject, ParamParseKey, Params, PatchRoutesOnNavigationFunction, Path, PathMatch, PathPattern, RelativeRoutingType, type RequestHandler, RouteObject, RouterInit, RouterState, type RoutesTestStubProps, ServerBuild, ServerRouter, type ServerRouterProps, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, ShouldRevalidateFunction, To, UIMatch, AssetsManifest as UNSAFE_AssetsManifest, MiddlewareEnabled as UNSAFE_MiddlewareEnabled, RSCDefaultRootErrorBoundary as UNSAFE_RSCDefaultRootErrorBoundary, RemixErrorBoundary as UNSAFE_RemixErrorBoundary, RouteModules as UNSAFE_RouteModules, ServerMode as UNSAFE_ServerMode, SingleFetchRedirectSymbol as UNSAFE_SingleFetchRedirectSymbol, decodeViaTurboStream as UNSAFE_decodeViaTurboStream, deserializeErrors as UNSAFE_deserializeErrors, getHydrationData as UNSAFE_getHydrationData, getPatchRoutesOnNavigationFunction as UNSAFE_getPatchRoutesOnNavigationFunction, getTurboStreamSingleFetchDataStrategy as UNSAFE_getTurboStreamSingleFetchDataStrategy, useFogOFWarDiscovery as UNSAFE_useFogOFWarDiscovery, createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createRoutesStub, createSession, createSessionStorage, href, isCookie, isSession, type BrowserCreateFromReadableStreamFunction as unstable_BrowserCreateFromReadableStreamFunction, type DecodeActionFunction as unstable_DecodeActionFunction, type DecodeFormStateFunction as unstable_DecodeFormStateFunction, type DecodeReplyFunction as unstable_DecodeReplyFunction, type EncodeReplyFunction as unstable_EncodeReplyFunction, unstable_InitialContext, type LoadServerActionFunction as unstable_LoadServerActionFunction, RSCHydratedRouter as unstable_RSCHydratedRouter, type RSCManifestPayload as unstable_RSCManifestPayload, type RSCMatch as unstable_RSCMatch, type RSCPayload as unstable_RSCPayload, type RSCRenderPayload as unstable_RSCRenderPayload, type RSCRouteConfig as unstable_RSCRouteConfig, type RSCRouteConfigEntry as unstable_RSCRouteConfigEntry, type RSCRouteManifest as unstable_RSCRouteManifest, type RSCRouteMatch as unstable_RSCRouteMatch, RSCStaticRouter as unstable_RSCStaticRouter, unstable_RouterContextProvider, type SSRCreateFromReadableStreamFunction as unstable_SSRCreateFromReadableStreamFunction, createCallServer as unstable_createCallServer, getRSCStream as unstable_getRSCStream, unstable_matchRSCServerRequest, routeRSCServerRequest as unstable_routeRSCServerRequest, setDevServerHooks as unstable_setDevServerHooks, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
|
|
1643
|
+
export { ActionFunction, AppLoadContext, Blocker, BlockerFunction, ClientActionFunction, ClientLoaderFunction, type Cookie, type CookieOptions, type CookieSignatureOptions, type CreateRequestHandlerFunction, DataRouteObject, Router as DataRouter, DataStrategyFunction, EntryContext, type FlashSessionData, HeadersFunction, HydrationState, IndexRouteObject, InitialEntry, type IsCookieFunction, type IsSessionFunction, LinksFunction, LoaderFunction, Location, MetaFunction, type NavigateFunction, NavigateOptions, Navigation, Action as NavigationType, NonIndexRouteObject, ParamParseKey, Params, PatchRoutesOnNavigationFunction, Path, PathMatch, PathPattern, RelativeRoutingType, type RequestHandler, RouteObject, RouterInit, RouterState, type RoutesTestStubProps, ServerBuild, ServerRouter, type ServerRouterProps, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, ShouldRevalidateFunction, To, UIMatch, AssetsManifest as UNSAFE_AssetsManifest, MiddlewareEnabled as UNSAFE_MiddlewareEnabled, RSCDefaultRootErrorBoundary as UNSAFE_RSCDefaultRootErrorBoundary, RemixErrorBoundary as UNSAFE_RemixErrorBoundary, RouteModules as UNSAFE_RouteModules, ServerMode as UNSAFE_ServerMode, SingleFetchRedirectSymbol as UNSAFE_SingleFetchRedirectSymbol, decodeViaTurboStream as UNSAFE_decodeViaTurboStream, deserializeErrors as UNSAFE_deserializeErrors, getHydrationData as UNSAFE_getHydrationData, getPatchRoutesOnNavigationFunction as UNSAFE_getPatchRoutesOnNavigationFunction, getTurboStreamSingleFetchDataStrategy as UNSAFE_getTurboStreamSingleFetchDataStrategy, useFogOFWarDiscovery as UNSAFE_useFogOFWarDiscovery, createCookie, createCookieSessionStorage, createMemorySessionStorage, createRequestHandler, createRoutesStub, createSession, createSessionStorage, href, isCookie, isSession, type BrowserCreateFromReadableStreamFunction as unstable_BrowserCreateFromReadableStreamFunction, type DecodeActionFunction as unstable_DecodeActionFunction, type DecodeFormStateFunction as unstable_DecodeFormStateFunction, type DecodeReplyFunction as unstable_DecodeReplyFunction, type EncodeReplyFunction as unstable_EncodeReplyFunction, unstable_InitialContext, type LoadServerActionFunction as unstable_LoadServerActionFunction, RSCHydratedRouter as unstable_RSCHydratedRouter, type RSCHydratedRouterProps as unstable_RSCHydratedRouterProps, type RSCManifestPayload as unstable_RSCManifestPayload, type RSCMatch as unstable_RSCMatch, type RSCPayload as unstable_RSCPayload, type RSCRenderPayload as unstable_RSCRenderPayload, type RSCRouteConfig as unstable_RSCRouteConfig, type RSCRouteConfigEntry as unstable_RSCRouteConfigEntry, type RSCRouteManifest as unstable_RSCRouteManifest, type RSCRouteMatch as unstable_RSCRouteMatch, RSCStaticRouter as unstable_RSCStaticRouter, type RSCStaticRouterProps as unstable_RSCStaticRouterProps, unstable_RouterContextProvider, type SSRCreateFromReadableStreamFunction as unstable_SSRCreateFromReadableStreamFunction, createCallServer as unstable_createCallServer, getRSCStream as unstable_getRSCStream, unstable_matchRSCServerRequest, routeRSCServerRequest as unstable_routeRSCServerRequest, setDevServerHooks as unstable_setDevServerHooks, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes };
|