react-router 6.27.0 → 7.0.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +309 -11
  2. package/README.md +1 -14
  3. package/dist/dom-export.d.ts +3 -0
  4. package/dist/dom-export.mjs +205 -0
  5. package/dist/dom-export.mjs.map +1 -0
  6. package/dist/index.d.ts +74 -29
  7. package/dist/index.mjs +11543 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/lib/components.d.ts +250 -35
  10. package/dist/lib/context.d.ts +18 -5
  11. package/dist/lib/dom/dom.d.ts +123 -0
  12. package/dist/lib/dom/global.d.ts +40 -0
  13. package/dist/lib/dom/lib.d.ts +940 -0
  14. package/dist/lib/dom/server.d.ts +41 -0
  15. package/dist/lib/dom/ssr/components.d.ts +123 -0
  16. package/dist/lib/dom/ssr/data.d.ts +7 -0
  17. package/dist/lib/dom/ssr/entry.d.ts +47 -0
  18. package/dist/lib/dom/ssr/errorBoundaries.d.ts +36 -0
  19. package/dist/lib/dom/ssr/errors.d.ts +2 -0
  20. package/dist/lib/dom/ssr/fallback.d.ts +2 -0
  21. package/dist/lib/dom/ssr/fog-of-war.d.ts +28 -0
  22. package/dist/lib/dom/ssr/invariant.d.ts +2 -0
  23. package/dist/lib/dom/ssr/links.d.ts +25 -0
  24. package/dist/lib/dom/ssr/markup.d.ts +5 -0
  25. package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
  26. package/dist/lib/dom/ssr/routes-test-stub.d.ts +59 -0
  27. package/dist/lib/dom/ssr/routes.d.ts +32 -0
  28. package/dist/lib/dom/ssr/server.d.ts +16 -0
  29. package/dist/lib/dom/ssr/single-fetch.d.ts +37 -0
  30. package/dist/lib/dom-export/dom-router-provider.d.ts +5 -0
  31. package/dist/lib/dom-export/hydrated-router.d.ts +5 -0
  32. package/dist/lib/dom-export.d.ts +3 -0
  33. package/dist/lib/hooks.d.ts +286 -57
  34. package/dist/lib/router/history.d.ts +253 -0
  35. package/dist/lib/router/links.d.ts +104 -0
  36. package/dist/lib/router/router.d.ts +540 -0
  37. package/dist/lib/router/utils.d.ts +505 -0
  38. package/dist/lib/server-runtime/build.d.ts +38 -0
  39. package/dist/lib/server-runtime/cookies.d.ts +62 -0
  40. package/dist/lib/server-runtime/crypto.d.ts +2 -0
  41. package/dist/lib/server-runtime/data.d.ts +15 -0
  42. package/dist/lib/server-runtime/dev.d.ts +8 -0
  43. package/dist/lib/server-runtime/entry.d.ts +3 -0
  44. package/dist/lib/server-runtime/errors.d.ts +51 -0
  45. package/dist/lib/server-runtime/headers.d.ts +3 -0
  46. package/dist/lib/server-runtime/invariant.d.ts +2 -0
  47. package/dist/lib/server-runtime/jsonify.d.ts +33 -0
  48. package/dist/lib/server-runtime/markup.d.ts +1 -0
  49. package/dist/lib/server-runtime/mode.d.ts +9 -0
  50. package/dist/lib/server-runtime/responses.d.ts +37 -0
  51. package/dist/lib/server-runtime/routeMatching.d.ts +8 -0
  52. package/dist/lib/server-runtime/routeModules.d.ts +212 -0
  53. package/dist/lib/server-runtime/routes.d.ts +31 -0
  54. package/dist/lib/server-runtime/server.d.ts +5 -0
  55. package/dist/lib/server-runtime/serverHandoff.d.ts +11 -0
  56. package/dist/lib/server-runtime/sessions/cookieStorage.d.ts +19 -0
  57. package/dist/lib/server-runtime/sessions/memoryStorage.d.ts +17 -0
  58. package/dist/lib/server-runtime/sessions.d.ts +140 -0
  59. package/dist/lib/server-runtime/single-fetch.d.ts +30 -0
  60. package/dist/lib/server-runtime/typecheck.d.ts +4 -0
  61. package/dist/lib/server-runtime/warnings.d.ts +1 -0
  62. package/dist/lib/types.d.ts +76 -0
  63. package/dist/lib/types.mjs +10 -0
  64. package/dist/main-dom-export.js +19 -0
  65. package/dist/main.js +1 -1
  66. package/dist/react-router-dom.development.js +199 -0
  67. package/dist/react-router-dom.development.js.map +1 -0
  68. package/dist/react-router-dom.production.min.js +12 -0
  69. package/dist/react-router-dom.production.min.js.map +1 -0
  70. package/dist/react-router.development.js +12281 -1141
  71. package/dist/react-router.development.js.map +1 -1
  72. package/dist/react-router.production.min.js +2 -2
  73. package/dist/react-router.production.min.js.map +1 -1
  74. package/dist/umd/react-router-dom.development.js +241 -0
  75. package/dist/umd/react-router-dom.development.js.map +1 -0
  76. package/dist/umd/react-router-dom.production.min.js +12 -0
  77. package/dist/umd/react-router-dom.production.min.js.map +1 -0
  78. package/dist/umd/react-router.development.js +12467 -1238
  79. package/dist/umd/react-router.development.js.map +1 -1
  80. package/dist/umd/react-router.production.min.js +2 -2
  81. package/dist/umd/react-router.production.min.js.map +1 -1
  82. package/package.json +35 -6
  83. package/dist/index.js +0 -1467
  84. package/dist/index.js.map +0 -1
@@ -0,0 +1,940 @@
1
+ import * as React from "react";
2
+ import type { History, To } from "../router/history";
3
+ import type { BlockerFunction, Fetcher, FutureConfig, GetScrollRestorationKeyFunction, HydrationState, RelativeRoutingType, Router as DataRouter } from "../router/router";
4
+ import type { DataStrategyFunction, HTMLFormMethod } from "../router/utils";
5
+ import "./global";
6
+ import type { SubmitOptions, URLSearchParamsInit, SubmitTarget, FetcherSubmitOptions } from "./dom";
7
+ import type { DiscoverBehavior, PrefetchBehavior, ScriptsProps } from "./ssr/components";
8
+ import type { RouteObject, NavigateOptions, PatchRoutesOnNavigationFunction } from "../context";
9
+ interface DOMRouterOpts {
10
+ basename?: string;
11
+ future?: Partial<FutureConfig>;
12
+ hydrationData?: HydrationState;
13
+ dataStrategy?: DataStrategyFunction;
14
+ patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
15
+ window?: Window;
16
+ }
17
+ /**
18
+ * @category Routers
19
+ */
20
+ export declare function createBrowserRouter(routes: RouteObject[], opts?: DOMRouterOpts): DataRouter;
21
+ /**
22
+ * @category Routers
23
+ */
24
+ export declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): DataRouter;
25
+ /**
26
+ * @category Types
27
+ */
28
+ export interface BrowserRouterProps {
29
+ basename?: string;
30
+ children?: React.ReactNode;
31
+ window?: Window;
32
+ }
33
+ /**
34
+ * A `<Router>` for use in web browsers. Provides the cleanest URLs.
35
+ *
36
+ * @category Router Components
37
+ */
38
+ export declare function BrowserRouter({ basename, children, window, }: BrowserRouterProps): React.JSX.Element;
39
+ /**
40
+ * @category Types
41
+ */
42
+ export interface HashRouterProps {
43
+ basename?: string;
44
+ children?: React.ReactNode;
45
+ window?: Window;
46
+ }
47
+ /**
48
+ * A `<Router>` for use in web browsers. Stores the location in the hash
49
+ * portion of the URL so it is not sent to the server.
50
+ *
51
+ * @category Router Components
52
+ */
53
+ export declare function HashRouter({ basename, children, window }: HashRouterProps): React.JSX.Element;
54
+ /**
55
+ * @category Types
56
+ */
57
+ export interface HistoryRouterProps {
58
+ basename?: string;
59
+ children?: React.ReactNode;
60
+ history: History;
61
+ }
62
+ /**
63
+ * A `<Router>` that accepts a pre-instantiated history object. It's important
64
+ * to note that using your own history object is highly discouraged and may add
65
+ * two versions of the history library to your bundles unless you use the same
66
+ * version of the history library that React Router uses internally.
67
+ *
68
+ * @name unstable_HistoryRouter
69
+ * @category Router Components
70
+ */
71
+ export declare function HistoryRouter({ basename, children, history, }: HistoryRouterProps): React.JSX.Element;
72
+ export declare namespace HistoryRouter {
73
+ var displayName: string;
74
+ }
75
+ /**
76
+ * @category Types
77
+ */
78
+ export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
79
+ /**
80
+ Defines the link discovery behavior
81
+
82
+ ```tsx
83
+ <Link /> // default ("render")
84
+ <Link discover="render" />
85
+ <Link discover="none" />
86
+ ```
87
+
88
+ - **render** - default, discover the route when the link renders
89
+ - **none** - don't eagerly discover, only discover if the link is clicked
90
+ */
91
+ discover?: DiscoverBehavior;
92
+ /**
93
+ Defines the data and module prefetching behavior for the link.
94
+
95
+ ```tsx
96
+ <Link /> // default
97
+ <Link prefetch="none" />
98
+ <Link prefetch="intent" />
99
+ <Link prefetch="render" />
100
+ <Link prefetch="viewport" />
101
+ ```
102
+
103
+ - **none** - default, no prefetching
104
+ - **intent** - prefetches when the user hovers or focuses the link
105
+ - **render** - prefetches when the link renders
106
+ - **viewport** - prefetches when the link is in the viewport, very useful for mobile
107
+
108
+ Prefetching is done with HTML `<link rel="prefetch">` tags. They are inserted after the link.
109
+
110
+ ```tsx
111
+ <a href="..." />
112
+ <a href="..." />
113
+ <link rel="prefetch" /> // might conditionally render
114
+ ```
115
+
116
+ Because of this, if you are using `nav :last-child` you will need to use `nav :last-of-type` so the styles don't conditionally fall off your last link (and any other similar selectors).
117
+ */
118
+ prefetch?: PrefetchBehavior;
119
+ /**
120
+ Will use document navigation instead of client side routing when the link is clicked: the browser will handle the transition normally (as if it were an `<a href>`).
121
+
122
+ ```tsx
123
+ <Link to="/logout" reloadDocument />
124
+ ```
125
+ */
126
+ reloadDocument?: boolean;
127
+ /**
128
+ Replaces the current entry in the history stack instead of pushing a new one onto it.
129
+
130
+ ```tsx
131
+ <Link replace />
132
+ ```
133
+
134
+ ```
135
+ # with a history stack like this
136
+ A -> B
137
+
138
+ # normal link click pushes a new entry
139
+ A -> B -> C
140
+
141
+ # but with `replace`, B is replaced by C
142
+ A -> C
143
+ ```
144
+ */
145
+ replace?: boolean;
146
+ /**
147
+ Adds persistent client side routing state to the next location.
148
+
149
+ ```tsx
150
+ <Link to="/somewhere/else" state={{ some: "value" }} />
151
+ ```
152
+
153
+ The location state is accessed from the `location`.
154
+
155
+ ```tsx
156
+ function SomeComp() {
157
+ const location = useLocation()
158
+ location.state; // { some: "value" }
159
+ }
160
+ ```
161
+
162
+ This state is inaccessible on the server as it is implemented on top of [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state)
163
+ */
164
+ state?: any;
165
+ /**
166
+ Prevents the scroll position from being reset to the top of the window when the link is clicked and the app is using {@link ScrollRestoration}. This only prevents new locations reseting scroll to the top, scroll position will be restored for back/forward button navigation.
167
+
168
+ ```tsx
169
+ <Link to="?tab=one" preventScrollReset />
170
+ ```
171
+ */
172
+ preventScrollReset?: boolean;
173
+ /**
174
+ Defines the relative path behavior for the link.
175
+
176
+ ```tsx
177
+ <Link to=".." /> // default: "route"
178
+ <Link relative="route" />
179
+ <Link relative="path" />
180
+ ```
181
+
182
+ Consider a route hierarchy where a parent route pattern is "blog" and a child route pattern is "blog/:slug/edit".
183
+
184
+ - **route** - default, resolves the link relative to the route pattern. In the example above a relative link of `".."` will remove both `:slug/edit` segments back to "/blog".
185
+ - **path** - relative to the path so `..` will only remove one URL segment up to "/blog/:slug"
186
+ */
187
+ relative?: RelativeRoutingType;
188
+ /**
189
+ Can be a string or a partial {@link Path}:
190
+
191
+ ```tsx
192
+ <Link to="/some/path" />
193
+
194
+ <Link
195
+ to={{
196
+ pathname: "/some/path",
197
+ search: "?query=string",
198
+ hash: "#hash",
199
+ }}
200
+ />
201
+ ```
202
+ */
203
+ to: To;
204
+ /**
205
+ Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) for this navigation.
206
+
207
+ ```jsx
208
+ <Link to={to} viewTransition>
209
+ Click me
210
+ </Link>
211
+ ```
212
+
213
+ To apply specific styles for the transition, see {@link useViewTransitionState}
214
+ */
215
+ viewTransition?: boolean;
216
+ }
217
+ /**
218
+ A progressively enhanced `<a href>` wrapper to enable navigation with client-side routing.
219
+
220
+ ```tsx
221
+ import { Link } from "react-router";
222
+
223
+ <Link to="/dashboard">Dashboard</Link>;
224
+
225
+ <Link
226
+ to={{
227
+ pathname: "/some/path",
228
+ search: "?query=string",
229
+ hash: "#hash",
230
+ }}
231
+ />
232
+ ```
233
+
234
+ @category Components
235
+ */
236
+ export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
237
+ /**
238
+ The object passed to {@link NavLink} `children`, `className`, and `style` prop callbacks to render and style the link based on its state.
239
+
240
+ ```
241
+ // className
242
+ <NavLink
243
+ to="/messages"
244
+ className={({ isActive, isPending }) =>
245
+ isPending ? "pending" : isActive ? "active" : ""
246
+ }
247
+ >
248
+ Messages
249
+ </NavLink>
250
+
251
+ // style
252
+ <NavLink
253
+ to="/messages"
254
+ style={({ isActive, isPending }) => {
255
+ return {
256
+ fontWeight: isActive ? "bold" : "",
257
+ color: isPending ? "red" : "black",
258
+ }
259
+ )}
260
+ />
261
+
262
+ // children
263
+ <NavLink to="/tasks">
264
+ {({ isActive, isPending }) => (
265
+ <span className={isActive ? "active" : ""}>Tasks</span>
266
+ )}
267
+ </NavLink>
268
+ ```
269
+
270
+ */
271
+ export type NavLinkRenderProps = {
272
+ /**
273
+ * Indicates if the link's URL matches the current location.
274
+ */
275
+ isActive: boolean;
276
+ /**
277
+ * Indicates if the pending location matches the link's URL.
278
+ */
279
+ isPending: boolean;
280
+ /**
281
+ * Indicates if a view transition to the link's URL is in progress. See {@link useViewTransitionState}
282
+ */
283
+ isTransitioning: boolean;
284
+ };
285
+ /**
286
+ * @category Types
287
+ */
288
+ export interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
289
+ /**
290
+ Can be regular React children or a function that receives an object with the active and pending states of the link.
291
+
292
+ ```tsx
293
+ <NavLink to="/tasks">
294
+ {({ isActive }) => (
295
+ <span className={isActive ? "active" : ""}>Tasks</span>
296
+ )}
297
+ </NavLink>
298
+ ```
299
+ */
300
+ children?: React.ReactNode | ((props: NavLinkRenderProps) => React.ReactNode);
301
+ /**
302
+ Changes the matching logic to make it case-sensitive:
303
+
304
+ | Link | URL | isActive |
305
+ | -------------------------------------------- | ------------- | -------- |
306
+ | `<NavLink to="/SpOnGe-bOB" />` | `/sponge-bob` | true |
307
+ | `<NavLink to="/SpOnGe-bOB" caseSensitive />` | `/sponge-bob` | false |
308
+ */
309
+ caseSensitive?: boolean;
310
+ /**
311
+ Classes are automatically applied to NavLink that correspond to {@link NavLinkRenderProps}.
312
+
313
+ ```css
314
+ a.active { color: red; }
315
+ a.pending { color: blue; }
316
+ a.transitioning {
317
+ view-transition-name: my-transition;
318
+ }
319
+ ```
320
+ */
321
+ className?: string | ((props: NavLinkRenderProps) => string | undefined);
322
+ /**
323
+ Changes the matching logic for the `active` and `pending` states to only match to the "end" of the {@link NavLinkProps.to}. If the URL is longer, it will no longer be considered active.
324
+
325
+ | Link | URL | isActive |
326
+ | ----------------------------- | ------------ | -------- |
327
+ | `<NavLink to="/tasks" />` | `/tasks` | true |
328
+ | `<NavLink to="/tasks" />` | `/tasks/123` | true |
329
+ | `<NavLink to="/tasks" end />` | `/tasks` | true |
330
+ | `<NavLink to="/tasks" end />` | `/tasks/123` | false |
331
+
332
+ `<NavLink to="/">` is an exceptional case because _every_ URL matches `/`. To avoid this matching every single route by default, it effectively ignores the `end` prop and only matches when you're at the root route.
333
+ */
334
+ end?: boolean;
335
+ style?: React.CSSProperties | ((props: NavLinkRenderProps) => React.CSSProperties | undefined);
336
+ }
337
+ /**
338
+ Wraps {@link Link | `<Link>`} with additional props for styling active and pending states.
339
+
340
+ - Automatically applies classes to the link based on its active and pending states, see {@link NavLinkProps.className}.
341
+ - Automatically applies `aria-current="page"` to the link when the link is active. See [`aria-current`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current) on MDN.
342
+
343
+ ```tsx
344
+ import { NavLink } from "react-router"
345
+ <NavLink to="/message" />
346
+ ```
347
+
348
+ States are available through the className, style, and children render props. See {@link NavLinkRenderProps}.
349
+
350
+ ```tsx
351
+ <NavLink
352
+ to="/messages"
353
+ className={({ isActive, isPending }) =>
354
+ isPending ? "pending" : isActive ? "active" : ""
355
+ }
356
+ >
357
+ Messages
358
+ </NavLink>
359
+ ```
360
+
361
+ @category Components
362
+ */
363
+ export declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
364
+ /**
365
+ * Form props shared by navigations and fetchers
366
+ */
367
+ interface SharedFormProps extends React.FormHTMLAttributes<HTMLFormElement> {
368
+ /**
369
+ * The HTTP verb to use when the form is submitted. Supports "get", "post",
370
+ * "put", "delete", and "patch".
371
+ *
372
+ * Native `<form>` only supports `get` and `post`, avoid the other verbs if
373
+ * you'd like to support progressive enhancement
374
+ */
375
+ method?: HTMLFormMethod;
376
+ /**
377
+ * The encoding type to use for the form submission.
378
+ */
379
+ encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
380
+ /**
381
+ * The URL to submit the form data to. If `undefined`, this defaults to the closest route in context.
382
+ */
383
+ action?: string;
384
+ /**
385
+ * Determines whether the form action is relative to the route hierarchy or
386
+ * the pathname. Use this if you want to opt out of navigating the route
387
+ * hierarchy and want to instead route based on /-delimited URL segments
388
+ */
389
+ relative?: RelativeRoutingType;
390
+ /**
391
+ * Prevent the scroll position from resetting to the top of the viewport on
392
+ * completion of the navigation when using the <ScrollRestoration> component
393
+ */
394
+ preventScrollReset?: boolean;
395
+ /**
396
+ * A function to call when the form is submitted. If you call
397
+ * `event.preventDefault()` then this form will not do anything.
398
+ */
399
+ onSubmit?: React.FormEventHandler<HTMLFormElement>;
400
+ }
401
+ /**
402
+ * Form props available to fetchers
403
+ * @category Types
404
+ */
405
+ export interface FetcherFormProps extends SharedFormProps {
406
+ }
407
+ /**
408
+ * Form props available to navigations
409
+ * @category Types
410
+ */
411
+ export interface FormProps extends SharedFormProps {
412
+ discover?: DiscoverBehavior;
413
+ /**
414
+ * Indicates a specific fetcherKey to use when using `navigate={false}` so you
415
+ * can pick up the fetcher's state in a different component in a {@link
416
+ * useFetcher}.
417
+ */
418
+ fetcherKey?: string;
419
+ /**
420
+ * Skips the navigation and uses a {@link useFetcher | fetcher} internally
421
+ * when `false`. This is essentially a shorthand for `useFetcher()` +
422
+ * `<fetcher.Form>` where you don't care about the resulting data in this
423
+ * component.
424
+ */
425
+ navigate?: boolean;
426
+ /**
427
+ * Forces a full document navigation instead of client side routing + data
428
+ * fetch.
429
+ */
430
+ reloadDocument?: boolean;
431
+ /**
432
+ * Replaces the current entry in the browser history stack when the form
433
+ * navigates. Use this if you don't want the user to be able to click "back"
434
+ * to the page with the form on it.
435
+ */
436
+ replace?: boolean;
437
+ /**
438
+ * State object to add to the history stack entry for this navigation
439
+ */
440
+ state?: any;
441
+ /**
442
+ * Enables a [View
443
+ * Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
444
+ * for this navigation. To apply specific styles during the transition see
445
+ * {@link useViewTransitionState}.
446
+ */
447
+ viewTransition?: boolean;
448
+ }
449
+ /**
450
+
451
+ A progressively enhanced HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) that submits data to actions via `fetch`, activating pending states in `useNavigation` which enables advanced user interfaces beyond a basic HTML form. After a form's action completes, all data on the page is automatically revalidated to keep the UI in sync with the data.
452
+
453
+ Because it uses the HTML form API, server rendered pages are interactive at a basic level before JavaScript loads. Instead of React Router managing the submission, the browser manages the submission as well as the pending states (like the spinning favicon). After JavaScript loads, React Router takes over enabling web application user experiences.
454
+
455
+ Form is most useful for submissions that should also change the URL or otherwise add an entry to the browser history stack. For forms that shouldn't manipulate the browser history stack, use [`<fetcher.Form>`][fetcher_form].
456
+
457
+ ```tsx
458
+ import { Form } from "react-router";
459
+
460
+ function NewEvent() {
461
+ return (
462
+ <Form action="/events" method="post">
463
+ <input name="title" type="text" />
464
+ <input name="description" type="text" />
465
+ </Form>
466
+ )
467
+ }
468
+ ```
469
+
470
+ @category Components
471
+ */
472
+ export declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
473
+ export type ScrollRestorationProps = ScriptsProps & {
474
+ /**
475
+ Defines the key used to restore scroll positions.
476
+
477
+ ```tsx
478
+ <ScrollRestoration
479
+ getKey={(location, matches) => {
480
+ // default behavior
481
+ return location.key
482
+ }}
483
+ />
484
+ ```
485
+ */
486
+ getKey?: GetScrollRestorationKeyFunction;
487
+ storageKey?: string;
488
+ };
489
+ /**
490
+ Emulates the browser's scroll restoration on location changes. Apps should only render one of these, right before the {@link Scripts} component.
491
+
492
+ ```tsx
493
+ import { ScrollRestoration } from "react-router";
494
+
495
+ export default function Root() {
496
+ return (
497
+ <html>
498
+ <body>
499
+ <ScrollRestoration />
500
+ <Scripts />
501
+ </body>
502
+ </html>
503
+ );
504
+ }
505
+ ```
506
+
507
+ This component renders an inline `<script>` to prevent scroll flashing. The `nonce` prop will be passed down to the script tag to allow CSP nonce usage.
508
+
509
+ ```tsx
510
+ <ScrollRestoration nonce={cspNonce} />
511
+ ```
512
+
513
+ @category Components
514
+ */
515
+ export declare function ScrollRestoration({ getKey, storageKey, ...props }: ScrollRestorationProps): React.JSX.Element | null;
516
+ export declare namespace ScrollRestoration {
517
+ var displayName: string;
518
+ }
519
+ /**
520
+ * Handles the click behavior for router `<Link>` components. This is useful if
521
+ * you need to create custom `<Link>` components with the same click behavior we
522
+ * use in our exported `<Link>`.
523
+ *
524
+ * @category Hooks
525
+ */
526
+ export declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, preventScrollReset, relative, viewTransition, }?: {
527
+ target?: React.HTMLAttributeAnchorTarget;
528
+ replace?: boolean;
529
+ state?: any;
530
+ preventScrollReset?: boolean;
531
+ relative?: RelativeRoutingType;
532
+ viewTransition?: boolean;
533
+ }): (event: React.MouseEvent<E, MouseEvent>) => void;
534
+ /**
535
+ Returns a tuple of the current URL's {@link URLSearchParams} and a function to update them. Setting the search params causes a navigation.
536
+
537
+ ```tsx
538
+ import { useSearchParams } from "react-router";
539
+
540
+ export function SomeComponent() {
541
+ const [searchParams, setSearchParams] = useSearchParams();
542
+ // ...
543
+ }
544
+ ```
545
+
546
+ @category Hooks
547
+ */
548
+ export declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
549
+ /**
550
+ Sets new search params and causes a navigation when called.
551
+
552
+ ```tsx
553
+ <button
554
+ onClick={() => {
555
+ const params = new URLSearchParams();
556
+ params.set("someKey", "someValue");
557
+ setSearchParams(params, {
558
+ preventScrollReset: true,
559
+ });
560
+ }}
561
+ />
562
+ ```
563
+
564
+ It also supports a function for setting new search params.
565
+
566
+ ```tsx
567
+ <button
568
+ onClick={() => {
569
+ setSearchParams((prev) => {
570
+ prev.set("someKey", "someValue");
571
+ return prev;
572
+ });
573
+ }}
574
+ />
575
+ ```
576
+ */
577
+ export type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
578
+ /**
579
+ * Submits a HTML `<form>` to the server without reloading the page.
580
+ */
581
+ export interface SubmitFunction {
582
+ (
583
+ /**
584
+ Can be multiple types of elements and objects
585
+
586
+ **`HTMLFormElement`**
587
+
588
+ ```tsx
589
+ <Form
590
+ onSubmit={(event) => {
591
+ submit(event.currentTarget);
592
+ }}
593
+ />
594
+ ```
595
+
596
+ **`FormData`**
597
+
598
+ ```tsx
599
+ const formData = new FormData();
600
+ formData.append("myKey", "myValue");
601
+ submit(formData, { method: "post" });
602
+ ```
603
+
604
+ **Plain object that will be serialized as `FormData`**
605
+
606
+ ```tsx
607
+ submit({ myKey: "myValue" }, { method: "post" });
608
+ ```
609
+
610
+ **Plain object that will be serialized as JSON**
611
+
612
+ ```tsx
613
+ submit(
614
+ { myKey: "myValue" },
615
+ { method: "post", encType: "application/json" }
616
+ );
617
+ ```
618
+ */
619
+ target: SubmitTarget,
620
+ /**
621
+ * Options that override the `<form>`'s own attributes. Required when
622
+ * submitting arbitrary data without a backing `<form>`.
623
+ */
624
+ options?: SubmitOptions): Promise<void>;
625
+ }
626
+ /**
627
+ * Submits a fetcher `<form>` to the server without reloading the page.
628
+ */
629
+ export interface FetcherSubmitFunction {
630
+ (
631
+ /**
632
+ Can be multiple types of elements and objects
633
+
634
+ **`HTMLFormElement`**
635
+
636
+ ```tsx
637
+ <fetcher.Form
638
+ onSubmit={(event) => {
639
+ fetcher.submit(event.currentTarget);
640
+ }}
641
+ />
642
+ ```
643
+
644
+ **`FormData`**
645
+
646
+ ```tsx
647
+ const formData = new FormData();
648
+ formData.append("myKey", "myValue");
649
+ fetcher.submit(formData, { method: "post" });
650
+ ```
651
+
652
+ **Plain object that will be serialized as `FormData`**
653
+
654
+ ```tsx
655
+ fetcher.submit({ myKey: "myValue" }, { method: "post" });
656
+ ```
657
+
658
+ **Plain object that will be serialized as JSON**
659
+
660
+ ```tsx
661
+ fetcher.submit(
662
+ { myKey: "myValue" },
663
+ { method: "post", encType: "application/json" }
664
+ );
665
+ ```
666
+
667
+ */
668
+ target: SubmitTarget, options?: FetcherSubmitOptions): Promise<void>;
669
+ }
670
+ /**
671
+ The imperative version of {@link Form | `<Form>`} that lets you submit a form from code instead of a user interaction.
672
+
673
+ ```tsx
674
+ import { useSubmit } from "react-router";
675
+
676
+ function SomeComponent() {
677
+ const submit = useSubmit();
678
+ return (
679
+ <Form
680
+ onChange={(event) => {
681
+ submit(event.currentTarget);
682
+ }}
683
+ />
684
+ );
685
+ }
686
+ ```
687
+
688
+ @category Hooks
689
+ */
690
+ export declare function useSubmit(): SubmitFunction;
691
+ /**
692
+ Resolves the URL to the closest route in the component hierarchy instead of the current URL of the app.
693
+
694
+ This is used internally by {@link Form} resolve the action to the closest route, but can be used generically as well.
695
+
696
+ ```tsx
697
+ import { useFormAction } from "react-router";
698
+
699
+ function SomeComponent() {
700
+ // closest route URL
701
+ let action = useFormAction();
702
+
703
+ // closest route URL + "destroy"
704
+ let destroyAction = useFormAction("destroy");
705
+ }
706
+ ```
707
+
708
+ @category Hooks
709
+ */
710
+ export declare function useFormAction(
711
+ /**
712
+ * The action to append to the closest route URL.
713
+ */
714
+ action?: string, { relative }?: {
715
+ relative?: RelativeRoutingType;
716
+ }): string;
717
+ /**
718
+ The return value of `useFetcher` that keeps track of the state of a fetcher.
719
+
720
+ ```tsx
721
+ let fetcher = useFetcher();
722
+ ```
723
+ */
724
+ export type FetcherWithComponents<TData> = Fetcher<TData> & {
725
+ /**
726
+ Just like {@link Form} except it doesn't cause a navigation.
727
+
728
+ ```tsx
729
+ function SomeComponent() {
730
+ const fetcher = useFetcher()
731
+ return (
732
+ <fetcher.Form method="post" action="/some/route">
733
+ <input type="text" />
734
+ </fetcher.Form>
735
+ )
736
+ }
737
+ ```
738
+ */
739
+ Form: React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>;
740
+ /**
741
+ Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
742
+
743
+ The `formData` can be multiple types:
744
+
745
+ - [`FormData`][form_data] - A `FormData` instance.
746
+ - [`HTMLFormElement`][html_form_element] - A [`<form>`][form_element] DOM element.
747
+ - `Object` - An object of key/value pairs that will be converted to a `FormData` instance by default. You can pass a more complex object and serialize it as JSON by specifying `encType: "application/json"`. See [`useSubmit`][use-submit] for more details.
748
+
749
+ If the method is `GET`, then the route [`loader`][loader] is being called and with the `formData` serialized to the url as [`URLSearchParams`][url_search_params]. If `DELETE`, `PATCH`, `POST`, or `PUT`, then the route [`action`][action] is being called with `formData` as the body.
750
+
751
+ ```tsx
752
+ // Submit a FormData instance (GET request)
753
+ const formData = new FormData();
754
+ fetcher.submit(formData);
755
+
756
+ // Submit the HTML form element
757
+ fetcher.submit(event.currentTarget.form, {
758
+ method: "POST",
759
+ });
760
+
761
+ // Submit key/value JSON as a FormData instance
762
+ fetcher.submit(
763
+ { serialized: "values" },
764
+ { method: "POST" }
765
+ );
766
+
767
+ // Submit raw JSON
768
+ fetcher.submit(
769
+ {
770
+ deeply: {
771
+ nested: {
772
+ json: "values",
773
+ },
774
+ },
775
+ },
776
+ {
777
+ method: "POST",
778
+ encType: "application/json",
779
+ }
780
+ );
781
+ ```
782
+ */
783
+ submit: FetcherSubmitFunction;
784
+ /**
785
+ Loads data from a route. Useful for loading data imperatively inside of user events outside of a normal button or form, like a combobox or search input.
786
+
787
+ ```tsx
788
+ let fetcher = useFetcher()
789
+
790
+ <input onChange={e => {
791
+ fetcher.load(`/search?q=${e.target.value}`)
792
+ }} />
793
+ ```
794
+ */
795
+ load: (href: string, opts?: {
796
+ /**
797
+ * Wraps the initial state update for this `fetcher.load` in a
798
+ * `ReactDOM.flushSync` call instead of the default `React.startTransition`.
799
+ * This allows you to perform synchronous DOM actions immediately after the
800
+ * update is flushed to the DOM.
801
+ */
802
+ flushSync?: boolean;
803
+ }) => Promise<void>;
804
+ };
805
+ /**
806
+ Useful for creating complex, dynamic user interfaces that require multiple, concurrent data interactions without causing a navigation.
807
+
808
+ Fetchers track their own, independent state and can be used to load data, submit forms, and generally interact with loaders and actions.
809
+
810
+ ```tsx
811
+ import { useFetcher } from "react-router"
812
+
813
+ function SomeComponent() {
814
+ let fetcher = useFetcher()
815
+
816
+ // states are available on the fetcher
817
+ fetcher.state // "idle" | "loading" | "submitting"
818
+ fetcher.data // the data returned from the action or loader
819
+
820
+ // render a form
821
+ <fetcher.Form method="post" />
822
+
823
+ // load data
824
+ fetcher.load("/some/route")
825
+
826
+ // submit data
827
+ fetcher.submit(someFormRef, { method: "post" })
828
+ fetcher.submit(someData, {
829
+ method: "post",
830
+ encType: "application/json"
831
+ })
832
+ }
833
+ ```
834
+
835
+ @category Hooks
836
+ */
837
+ export declare function useFetcher<TData = any>({ key, }?: {
838
+ /**
839
+ By default, `useFetcher` generate a unique fetcher scoped to that component. If you want to identify a fetcher with your own key such that you can access it from elsewhere in your app, you can do that with the `key` option:
840
+
841
+ ```tsx
842
+ function SomeComp() {
843
+ let fetcher = useFetcher({ key: "my-key" })
844
+ // ...
845
+ }
846
+
847
+ // Somewhere else
848
+ function AnotherComp() {
849
+ // this will be the same fetcher, sharing the state across the app
850
+ let fetcher = useFetcher({ key: "my-key" });
851
+ // ...
852
+ }
853
+ ```
854
+ */
855
+ key?: string;
856
+ }): FetcherWithComponents<TData>;
857
+ /**
858
+ Returns an array of all in-flight fetchers. This is useful for components throughout the app that didn't create the fetchers but want to use their submissions to participate in optimistic UI.
859
+
860
+ ```tsx
861
+ import { useFetchers } from "react-router";
862
+
863
+ function SomeComponent() {
864
+ const fetchers = useFetchers();
865
+ fetchers[0].formData; // FormData
866
+ fetchers[0].state; // etc.
867
+ // ...
868
+ }
869
+ ```
870
+
871
+ @category Hooks
872
+ */
873
+ export declare function useFetchers(): (Fetcher & {
874
+ key: string;
875
+ })[];
876
+ /**
877
+ * When rendered inside a RouterProvider, will restore scroll positions on navigations
878
+ */
879
+ export declare function useScrollRestoration({ getKey, storageKey, }?: {
880
+ getKey?: GetScrollRestorationKeyFunction;
881
+ storageKey?: string;
882
+ }): void;
883
+ /**
884
+ * Setup a callback to be fired on the window's `beforeunload` event.
885
+ *
886
+ * @category Hooks
887
+ */
888
+ export declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
889
+ capture?: boolean;
890
+ }): void;
891
+ /**
892
+ Wrapper around useBlocker to show a window.confirm prompt to users instead of building a custom UI with {@link useBlocker}.
893
+
894
+ The `unstable_` flag will not be removed because this technique has a lot of rough edges and behaves very differently (and incorrectly sometimes) across browsers if users click addition back/forward navigations while the confirmation is open. Use at your own risk.
895
+
896
+ ```tsx
897
+ function ImportantForm() {
898
+ let [value, setValue] = React.useState("");
899
+
900
+ // Block navigating elsewhere when data has been entered into the input
901
+ unstable_usePrompt({
902
+ message: "Are you sure?",
903
+ when: ({ currentLocation, nextLocation }) =>
904
+ value !== "" &&
905
+ currentLocation.pathname !== nextLocation.pathname,
906
+ });
907
+
908
+ return (
909
+ <Form method="post">
910
+ <label>
911
+ Enter some important data:
912
+ <input
913
+ name="data"
914
+ value={value}
915
+ onChange={(e) => setValue(e.target.value)}
916
+ />
917
+ </label>
918
+ <button type="submit">Save</button>
919
+ </Form>
920
+ );
921
+ }
922
+ ```
923
+
924
+ @category Hooks
925
+ @name unstable_usePrompt
926
+ */
927
+ export declare function usePrompt({ when, message, }: {
928
+ when: boolean | BlockerFunction;
929
+ message: string;
930
+ }): void;
931
+ /**
932
+ This hook returns `true` when there is an active [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) to the specified location. This can be used to apply finer-grained styles to elements to further customize the view transition. This requires that view transitions have been enabled for the given navigation via {@link LinkProps.viewTransition} (or the `Form`, `submit`, or `navigate` call)
933
+
934
+ @category Hooks
935
+ @name useViewTransitionState
936
+ */
937
+ export declare function useViewTransitionState(to: To, opts?: {
938
+ relative?: RelativeRoutingType;
939
+ }): boolean;
940
+ export {};