react-router 7.7.0-pre.1 → 7.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +9 -7
  2. package/dist/development/{browser-BSrXyLft.d.mts → browser-CcxeZJcQ.d.mts} +3 -30
  3. package/dist/development/{chunk-6ZHKKNZG.js → chunk-4ADB4KIO.js} +170 -140
  4. package/dist/development/{chunk-YNUF36W5.mjs → chunk-EF7DTUVF.mjs} +52 -22
  5. package/dist/{production/chunk-KZZC37RO.mjs → development/chunk-T3VM44WY.mjs} +31 -26
  6. package/dist/development/{chunk-Z7T4GLA7.js → chunk-V6PEDDZI.js} +1 -1
  7. package/dist/development/components-DzqPLVI1.d.mts +464 -0
  8. package/dist/development/dom-export.d.mts +3 -3
  9. package/dist/development/dom-export.js +3 -3
  10. package/dist/development/dom-export.mjs +3 -3
  11. package/dist/{production/index-react-server-client-DOK8MfYF.d.mts → development/index-react-server-client-CUidsuu_.d.mts} +2 -2
  12. package/dist/development/{index-react-server-client-LrDNRnlX.d.ts → index-react-server-client-kY8DvDF3.d.ts} +177 -529
  13. package/dist/development/index-react-server-client.d.mts +3 -3
  14. package/dist/development/index-react-server-client.d.ts +2 -2
  15. package/dist/development/index-react-server-client.js +10 -4
  16. package/dist/development/index-react-server-client.mjs +9 -3
  17. package/dist/development/index-react-server.js +20 -6
  18. package/dist/development/index-react-server.mjs +21 -6
  19. package/dist/development/index.d.mts +396 -9
  20. package/dist/development/index.d.ts +372 -12
  21. package/dist/development/index.js +131 -120
  22. package/dist/development/index.mjs +9 -3
  23. package/dist/development/lib/types/internal.d.mts +1 -1
  24. package/dist/development/lib/types/internal.d.ts +1 -1
  25. package/dist/development/lib/types/internal.js +1 -1
  26. package/dist/development/lib/types/internal.mjs +1 -1
  27. package/dist/{production/route-data-DAw7Esur.d.mts → development/route-data-DjzmHYNR.d.mts} +1 -1
  28. package/dist/{production/route-data-7aXBQ4I3.d.ts → development/routeModules-g5PTiDfO.d.ts} +156 -156
  29. package/dist/production/{browser-BSrXyLft.d.mts → browser-CcxeZJcQ.d.mts} +3 -30
  30. package/dist/production/{chunk-W77PDD2Y.js → chunk-2TYFPE3B.js} +170 -140
  31. package/dist/production/{chunk-SH44XSL4.js → chunk-5KHO4FML.js} +1 -1
  32. package/dist/{development/chunk-YP7CIEHK.mjs → production/chunk-GNZILI6H.mjs} +31 -26
  33. package/dist/production/{chunk-4FKAWASN.mjs → chunk-WPPIQDYG.mjs} +52 -22
  34. package/dist/production/components-DzqPLVI1.d.mts +464 -0
  35. package/dist/production/dom-export.d.mts +3 -3
  36. package/dist/production/dom-export.js +3 -3
  37. package/dist/production/dom-export.mjs +3 -3
  38. package/dist/{development/index-react-server-client-DOK8MfYF.d.mts → production/index-react-server-client-CUidsuu_.d.mts} +2 -2
  39. package/dist/production/{index-react-server-client-LrDNRnlX.d.ts → index-react-server-client-kY8DvDF3.d.ts} +177 -529
  40. package/dist/production/index-react-server-client.d.mts +3 -3
  41. package/dist/production/index-react-server-client.d.ts +2 -2
  42. package/dist/production/index-react-server-client.js +10 -4
  43. package/dist/production/index-react-server-client.mjs +9 -3
  44. package/dist/production/index-react-server.js +20 -6
  45. package/dist/production/index-react-server.mjs +21 -6
  46. package/dist/production/index.d.mts +396 -9
  47. package/dist/production/index.d.ts +372 -12
  48. package/dist/production/index.js +131 -120
  49. package/dist/production/index.mjs +9 -3
  50. package/dist/production/lib/types/internal.d.mts +1 -1
  51. package/dist/production/lib/types/internal.d.ts +1 -1
  52. package/dist/production/lib/types/internal.js +1 -1
  53. package/dist/production/lib/types/internal.mjs +1 -1
  54. package/dist/{development/route-data-DAw7Esur.d.mts → production/route-data-DjzmHYNR.d.mts} +1 -1
  55. package/dist/{development/route-data-7aXBQ4I3.d.ts → production/routeModules-g5PTiDfO.d.ts} +156 -156
  56. package/package.json +1 -1
  57. package/dist/development/components-IaVqGBuO.d.mts +0 -816
  58. package/dist/production/components-IaVqGBuO.d.mts +0 -816
@@ -1,7 +1,7 @@
1
- import { d as Router, e as RouteModules, D as DataStrategyFunction, I as InitialEntry, H as HydrationState, f as IndexRouteObject, g as LoaderFunction, A as ActionFunction, h as MetaFunction, i as LinksFunction, j as NonIndexRouteObject, k as AppLoadContext, l as unstable_RouterContextProvider, m as MiddlewareEnabled, n as unstable_InitialContext, E as Equal, o as ClientActionFunction, p as ClientLoaderFunction, q as HeadersFunction, r as ShouldRevalidateFunction, a as Location, s as Params, t as RouterInit, v as RouterState, w as PatchRoutesOnNavigationFunction, x as DataRouteObject, y as Path } from './route-data-7aXBQ4I3.js';
2
- export { $ as ActionFunctionArgs, V as Blocker, W as BlockerFunction, aF as ClientActionFunctionArgs, aG as ClientLoaderFunctionArgs, az as DataRouteMatch, a0 as DataStrategyFunctionArgs, a1 as DataStrategyMatch, a2 as DataStrategyResult, a4 as ErrorResponse, K as Fetcher, a5 as FormEncType, a6 as FormMethod, aL as Future, B as GetScrollPositionFunction, F as GetScrollRestorationKeyFunction, a7 as HTMLFormMethod, aH as HeadersArgs, aK as HtmlLinkDescriptor, ap as IDLE_BLOCKER, ao as IDLE_FETCHER, an as IDLE_NAVIGATION, a8 as LazyRouteFunction, L as LinkDescriptor, a9 as LoaderFunctionArgs, aI as MetaArgs, M as MetaDescriptor, aA as NavigateOptions, O as Navigation, Q as NavigationStates, ak as NavigationType, aB as Navigator, aJ as PageLinkDescriptor, ab as ParamParseKey, aC as PatchRoutesOnNavigationFunctionArgs, ac as PathMatch, ad as PathParam, ae as PathPattern, af as RedirectFunction, U as RelativeRoutingType, _ as RevalidationState, aD as RouteMatch, aE as RouteObject, Z as RouterFetchOptions, Y as RouterNavigateOptions, X as RouterSubscriber, ah as ShouldRevalidateFunctionArgs, z as StaticHandler, J as StaticHandlerContext, T as To, ai as UIMatch, aR as UNSAFE_DataRouterContext, aS as UNSAFE_DataRouterStateContext, a3 as UNSAFE_DataWithResponseInit, aQ as UNSAFE_ErrorResponseImpl, aT as UNSAFE_FetchersContext, aU as UNSAFE_LocationContext, aV as UNSAFE_NavigationContext, aW as UNSAFE_RouteContext, aX as UNSAFE_ViewTransitionContext, aN as UNSAFE_createBrowserHistory, aP as UNSAFE_createRouter, aO as UNSAFE_invariant, al as createPath, aq as data, ar as generatePath, as as isRouteErrorResponse, at as matchPath, au as matchRoutes, am as parsePath, av as redirect, aw as redirectDocument, ax as replace, ay as resolvePath, aa as unstable_MiddlewareFunction, ag as unstable_RouterContext, aM as unstable_SerializesTo, aj as unstable_createContext } from './route-data-7aXBQ4I3.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-LrDNRnlX.js';
4
- export { h as Await, b as AwaitProps, af as BrowserRouter, $ as BrowserRouterProps, a0 as DOMRouterOpts, a6 as FetcherFormProps, ab as FetcherSubmitFunction, av as FetcherSubmitOptions, ac as FetcherWithComponents, ak as Form, a7 as FormProps, aM as HandleDataRequestFunction, aN as HandleDocumentRequestFunction, aO as HandleErrorFunction, ag as HashRouter, a1 as HashRouterProps, a2 as HistoryRouterProps, I as IndexRouteProps, L as LayoutRouteProps, ah as Link, a3 as LinkProps, aI as Links, i as MemoryRouter, M as MemoryRouterOpts, c as MemoryRouterProps, aH as Meta, aj as NavLink, a4 as NavLinkProps, a5 as NavLinkRenderProps, j as Navigate, t as NavigateFunction, N as NavigateProps, k as Outlet, O as OutletProps, aw as ParamKeyValuePair, P as PathRouteProps, aK 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, aJ as Scripts, aL as ScriptsProps, al as ScrollRestoration, a8 as ScrollRestorationProps, aP as ServerEntryModule, a9 as SetURLSearchParams, aF as StaticRouter, aB as StaticRouterProps, aG as StaticRouterProvider, aC as StaticRouterProviderProps, aa as SubmitFunction, ax as SubmitOptions, az as SubmitTarget, aV as UNSAFE_FrameworkContext, aW as UNSAFE_createClientRoutes, aX as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, aQ as UNSAFE_hydrationRouteProperties, aR as UNSAFE_mapRouteProperties, aY as UNSAFE_shouldHydrateRouteLoader, aZ as UNSAFE_useScrollRestoration, aS as UNSAFE_withComponentProps, aU as UNSAFE_withErrorBoundaryProps, aT as UNSAFE_withHydrateFallbackProps, ay as URLSearchParamsInit, ad as createBrowserRouter, ae as createHashRouter, p as createMemoryRouter, q as createRoutesFromChildren, r as createRoutesFromElements, aA as createSearchParams, aD as createStaticHandler, aE as createStaticRouter, s as renderMatches, ai as unstable_HistoryRouter, at as unstable_usePrompt, v as useActionData, w as useAsyncError, x as useAsyncValue, as as useBeforeUnload, u as useBlocker, aq as useFetcher, ar as useFetchers, ap as useFormAction, y as useHref, z as useInRouterContext, am as useLinkClickHandler, B as useLoaderData, C as useLocation, D as useMatch, G as useMatches, J as useNavigate, K as useNavigation, Q as useNavigationType, T as useOutlet, U as useOutletContext, V as useParams, W as useResolvedPath, X as useRevalidator, Y as useRouteError, Z as useRouteLoaderData, _ as useRoutes, an as useSearchParams, ao as useSubmit, au as useViewTransitionState } from './index-react-server-client-LrDNRnlX.js';
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-g5PTiDfO.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-g5PTiDfO.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-kY8DvDF3.js';
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, aq as HandleDataRequestFunction, ar as HandleDocumentRequestFunction, as 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, 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, at 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, aC as UNSAFE_FrameworkContext, aw as UNSAFE_WithComponentProps, aA as UNSAFE_WithErrorBoundaryProps, ay as UNSAFE_WithHydrateFallbackProps, aD as UNSAFE_createClientRoutes, aE as UNSAFE_createClientRoutesWithHMRRevalidationOptOut, au as UNSAFE_hydrationRouteProperties, av as UNSAFE_mapRouteProperties, aF as UNSAFE_shouldHydrateRouteLoader, aG as UNSAFE_useScrollRestoration, ax as UNSAFE_withComponentProps, aB as UNSAFE_withErrorBoundaryProps, az 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-kY8DvDF3.js';
5
5
  import * as React from 'react';
6
6
  import React__default, { ReactElement } from 'react';
7
7
  import { ParseOptions, SerializeOptions } from 'cookie';
@@ -26,6 +26,373 @@ declare enum ServerMode {
26
26
  Test = "test"
27
27
  }
28
28
 
29
+ /**
30
+ Resolves a URL against the current location.
31
+
32
+ ```tsx
33
+ import { useHref } from "react-router"
34
+
35
+ function SomeComponent() {
36
+ let href = useHref("some/where");
37
+ // "/resolved/some/where"
38
+ }
39
+ ```
40
+
41
+ @category Hooks
42
+ */
43
+ declare function useHref(to: To, { relative }?: {
44
+ relative?: RelativeRoutingType;
45
+ }): string;
46
+ /**
47
+ * Returns true if this component is a descendant of a Router, useful to ensure
48
+ * a component is used within a Router.
49
+ *
50
+ * @category Hooks
51
+ */
52
+ declare function useInRouterContext(): boolean;
53
+ /**
54
+ Returns the current {@link Location}. This can be useful if you'd like to perform some side effect whenever it changes.
55
+
56
+ ```tsx
57
+ import * as React from 'react'
58
+ import { useLocation } from 'react-router'
59
+
60
+ function SomeComponent() {
61
+ let location = useLocation()
62
+
63
+ React.useEffect(() => {
64
+ // Google Analytics
65
+ ga('send', 'pageview')
66
+ }, [location]);
67
+
68
+ return (
69
+ // ...
70
+ );
71
+ }
72
+ ```
73
+
74
+ @category Hooks
75
+ */
76
+ declare function useLocation(): Location;
77
+ /**
78
+ * Returns the current navigation action which describes how the router came to
79
+ * the current location, either by a pop, push, or replace on the history stack.
80
+ *
81
+ * @category Hooks
82
+ */
83
+ declare function useNavigationType(): Action;
84
+ /**
85
+ * Returns a PathMatch object if the given pattern matches the current URL.
86
+ * This is useful for components that need to know "active" state, e.g.
87
+ * `<NavLink>`.
88
+ *
89
+ * @category Hooks
90
+ */
91
+ declare function useMatch<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path): PathMatch<ParamKey> | null;
92
+ /**
93
+ * The interface for the navigate() function returned from useNavigate().
94
+ */
95
+ interface NavigateFunction {
96
+ (to: To, options?: NavigateOptions): void | Promise<void>;
97
+ (delta: number): void | Promise<void>;
98
+ }
99
+ /**
100
+ Returns a function that lets you navigate programmatically in the browser in response to user interactions or effects.
101
+
102
+ ```tsx
103
+ import { useNavigate } from "react-router";
104
+
105
+ function SomeComponent() {
106
+ let navigate = useNavigate();
107
+ return (
108
+ <button
109
+ onClick={() => {
110
+ navigate(-1);
111
+ }}
112
+ />
113
+ );
114
+ }
115
+ ```
116
+
117
+ It's often better to use {@link redirect} in {@link ActionFunction | actions} and {@link LoaderFunction | loaders} than this hook.
118
+
119
+ @category Hooks
120
+ */
121
+ declare function useNavigate(): NavigateFunction;
122
+ /**
123
+ * Returns the parent route {@link OutletProps.context | `<Outlet context>`}.
124
+ *
125
+ * @category Hooks
126
+ */
127
+ declare function useOutletContext<Context = unknown>(): Context;
128
+ /**
129
+ * Returns the element for the child route at this level of the route
130
+ * hierarchy. Used internally by `<Outlet>` to render child routes.
131
+ *
132
+ * @category Hooks
133
+ */
134
+ declare function useOutlet(context?: unknown): React.ReactElement | null;
135
+ /**
136
+ Returns an object of key/value pairs of the dynamic params from the current URL that were matched by the routes. Child routes inherit all params from their parent routes.
137
+
138
+ ```tsx
139
+ import { useParams } from "react-router"
140
+
141
+ function SomeComponent() {
142
+ let params = useParams()
143
+ params.postId
144
+ }
145
+ ```
146
+
147
+ Assuming a route pattern like `/posts/:postId` is matched by `/posts/123` then `params.postId` will be `"123"`.
148
+
149
+ @category Hooks
150
+ */
151
+ declare function useParams<ParamsOrKey extends string | Record<string, string | undefined> = string>(): Readonly<[
152
+ ParamsOrKey
153
+ ] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>>;
154
+ /**
155
+ Resolves the pathname of the given `to` value against the current location. Similar to {@link useHref}, but returns a {@link Path} instead of a string.
156
+
157
+ ```tsx
158
+ import { useResolvedPath } from "react-router"
159
+
160
+ function SomeComponent() {
161
+ // if the user is at /dashboard/profile
162
+ let path = useResolvedPath("../accounts")
163
+ path.pathname // "/dashboard/accounts"
164
+ path.search // ""
165
+ path.hash // ""
166
+ }
167
+ ```
168
+
169
+ @category Hooks
170
+ */
171
+ declare function useResolvedPath(to: To, { relative }?: {
172
+ relative?: RelativeRoutingType;
173
+ }): Path;
174
+ /**
175
+ Hook version of {@link Routes | `<Routes>`} that uses objects instead of components. These objects have the same properties as the component props.
176
+
177
+ The return value of `useRoutes` is either a valid React element you can use to render the route tree, or `null` if nothing matched.
178
+
179
+ ```tsx
180
+ import * as React from "react";
181
+ import { useRoutes } from "react-router";
182
+
183
+ function App() {
184
+ let element = useRoutes([
185
+ {
186
+ path: "/",
187
+ element: <Dashboard />,
188
+ children: [
189
+ {
190
+ path: "messages",
191
+ element: <DashboardMessages />,
192
+ },
193
+ { path: "tasks", element: <DashboardTasks /> },
194
+ ],
195
+ },
196
+ { path: "team", element: <AboutPage /> },
197
+ ]);
198
+
199
+ return element;
200
+ }
201
+ ```
202
+
203
+ @category Hooks
204
+ */
205
+ declare function useRoutes(routes: RouteObject[], locationArg?: Partial<Location> | string): React.ReactElement | null;
206
+ /**
207
+ Returns the current navigation, defaulting to an "idle" navigation when no navigation is in progress. You can use this to render pending UI (like a global spinner) or read FormData from a form navigation.
208
+
209
+ ```tsx
210
+ import { useNavigation } from "react-router"
211
+
212
+ function SomeComponent() {
213
+ let navigation = useNavigation();
214
+ navigation.state
215
+ navigation.formData
216
+ // etc.
217
+ }
218
+ ```
219
+
220
+ @category Hooks
221
+ */
222
+ declare function useNavigation(): Navigation;
223
+ /**
224
+ Revalidate the data on the page for reasons outside of normal data mutations like window focus or polling on an interval.
225
+
226
+ ```tsx
227
+ import { useRevalidator } from "react-router";
228
+
229
+ function WindowFocusRevalidator() {
230
+ const revalidator = useRevalidator();
231
+
232
+ useFakeWindowFocus(() => {
233
+ revalidator.revalidate();
234
+ });
235
+
236
+ return (
237
+ <div hidden={revalidator.state === "idle"}>
238
+ Revalidating...
239
+ </div>
240
+ );
241
+ }
242
+ ```
243
+
244
+ Note that page data is already revalidated automatically after actions. If you find yourself using this for normal CRUD operations on your data in response to user interactions, you're probably not taking advantage of the other APIs like {@link useFetcher}, {@link Form}, {@link useSubmit} that do this automatically.
245
+
246
+ @category Hooks
247
+ */
248
+ declare function useRevalidator(): {
249
+ revalidate: () => Promise<void>;
250
+ state: Router["state"]["revalidation"];
251
+ };
252
+ /**
253
+ * Returns the active route matches, useful for accessing loaderData for
254
+ * parent/child routes or the route "handle" property
255
+ *
256
+ * @category Hooks
257
+ */
258
+ declare function useMatches(): UIMatch[];
259
+ /**
260
+ Returns the data from the closest route {@link LoaderFunction | loader} or {@link ClientLoaderFunction | client loader}.
261
+
262
+ ```tsx
263
+ import { useLoaderData } from "react-router"
264
+
265
+ export async function loader() {
266
+ return await fakeDb.invoices.findAll();
267
+ }
268
+
269
+ export default function Invoices() {
270
+ let invoices = useLoaderData<typeof loader>();
271
+ // ...
272
+ }
273
+ ```
274
+
275
+ @category Hooks
276
+ */
277
+ declare function useLoaderData<T = any>(): SerializeFrom<T>;
278
+ /**
279
+ Returns the loader data for a given route by route ID.
280
+
281
+ ```tsx
282
+ import { useRouteLoaderData } from "react-router";
283
+
284
+ function SomeComponent() {
285
+ const { user } = useRouteLoaderData("root");
286
+ }
287
+ ```
288
+
289
+ Route IDs are created automatically. They are simply the path of the route file relative to the app folder without the extension.
290
+
291
+ | Route Filename | Route ID |
292
+ | -------------------------- | -------------------- |
293
+ | `app/root.tsx` | `"root"` |
294
+ | `app/routes/teams.tsx` | `"routes/teams"` |
295
+ | `app/whatever/teams.$id.tsx` | `"whatever/teams.$id"` |
296
+
297
+ If you created an ID manually, you can use that instead:
298
+
299
+ ```tsx
300
+ route("/", "containers/app.tsx", { id: "app" }})
301
+ ```
302
+
303
+ @category Hooks
304
+ */
305
+ declare function useRouteLoaderData<T = any>(routeId: string): SerializeFrom<T> | undefined;
306
+ /**
307
+ Returns the action data from the most recent POST navigation form submission or `undefined` if there hasn't been one.
308
+
309
+ ```tsx
310
+ import { Form, useActionData } from "react-router"
311
+
312
+ export async function action({ request }) {
313
+ const body = await request.formData()
314
+ const name = body.get("visitorsName")
315
+ return { message: `Hello, ${name}` }
316
+ }
317
+
318
+ export default function Invoices() {
319
+ const data = useActionData()
320
+ return (
321
+ <Form method="post">
322
+ <input type="text" name="visitorsName" />
323
+ {data ? data.message : "Waiting..."}
324
+ </Form>
325
+ )
326
+ }
327
+ ```
328
+
329
+ @category Hooks
330
+ */
331
+ declare function useActionData<T = any>(): SerializeFrom<T> | undefined;
332
+ /**
333
+ Accesses the error thrown during an {@link ActionFunction | action}, {@link LoaderFunction | loader}, or component render to be used in a route module Error Boundary.
334
+
335
+ ```tsx
336
+ export function ErrorBoundary() {
337
+ const error = useRouteError();
338
+ return <div>{error.message}</div>;
339
+ }
340
+ ```
341
+
342
+ @category Hooks
343
+ */
344
+ declare function useRouteError(): unknown;
345
+ /**
346
+ Returns the resolved promise value from the closest {@link Await | `<Await>`}.
347
+
348
+ ```tsx
349
+ function SomeDescendant() {
350
+ const value = useAsyncValue();
351
+ // ...
352
+ }
353
+
354
+ // somewhere in your app
355
+ <Await resolve={somePromise}>
356
+ <SomeDescendant />
357
+ </Await>
358
+ ```
359
+
360
+ @category Hooks
361
+ */
362
+ declare function useAsyncValue(): unknown;
363
+ /**
364
+ Returns the rejection value from the closest {@link Await | `<Await>`}.
365
+
366
+ ```tsx
367
+ import { Await, useAsyncError } from "react-router"
368
+
369
+ function ErrorElement() {
370
+ const error = useAsyncError();
371
+ return (
372
+ <p>Uh Oh, something went wrong! {error.message}</p>
373
+ );
374
+ }
375
+
376
+ // somewhere in your app
377
+ <Await
378
+ resolve={promiseThatRejects}
379
+ errorElement={<ErrorElement />}
380
+ />
381
+ ```
382
+
383
+ @category Hooks
384
+ */
385
+ declare function useAsyncError(): unknown;
386
+ /**
387
+ * Allow the application to block navigations within the SPA and present the
388
+ * user a confirmation dialog to confirm the navigation. Mostly used to avoid
389
+ * using half-filled form data. This does not handle hard-reloads or
390
+ * cross-origin navigations.
391
+ *
392
+ * @category Hooks
393
+ */
394
+ declare function useBlocker(shouldBlock: boolean | BlockerFunction): Blocker;
395
+
29
396
  interface ServerRouterProps {
30
397
  context: EntryContext;
31
398
  url: string | URL;
@@ -471,13 +838,6 @@ type BrowserCreateFromReadableStreamFunction = (body: ReadableStream<Uint8Array>
471
838
  type EncodeReplyFunction = (args: unknown[], options: {
472
839
  temporaryReferences: unknown;
473
840
  }) => Promise<BodyInit>;
474
- declare global {
475
- interface Window {
476
- __router: Router;
477
- __routerInitialized: boolean;
478
- __routerActionID: number;
479
- }
480
- }
481
841
  declare function createCallServer({ createFromReadableStream, createTemporaryReferenceSet, encodeReply, fetch: fetchImplementation, }: {
482
842
  createFromReadableStream: BrowserCreateFromReadableStreamFunction;
483
843
  createTemporaryReferenceSet: () => unknown;
@@ -553,4 +913,4 @@ declare function getHydrationData(state: {
553
913
 
554
914
  declare const unstable_matchRSCServerRequest: typeof matchRSCServerRequest;
555
915
 
556
- export { ActionFunction, AppLoadContext, 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, NonIndexRouteObject, Params, PatchRoutesOnNavigationFunction, Path, type RequestHandler, RouterInit, RouterState, type RoutesTestStubProps, ServerBuild, ServerRouter, type ServerRouterProps, type Session, type SessionData, type SessionIdStorageStrategy, type SessionStorage, ShouldRevalidateFunction, 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 };
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 };