react-router 0.0.0-experimental-e56aa53bc → 0.0.0-experimental-e6fb6e074

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 (65) hide show
  1. package/CHANGELOG.md +18 -734
  2. package/README.md +14 -5
  3. package/dist/index.d.ts +30 -0
  4. package/dist/index.js +1501 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/components.d.ts +157 -0
  7. package/dist/lib/context.d.ts +102 -0
  8. package/dist/lib/deprecations.d.ts +4 -0
  9. package/dist/lib/hooks.d.ts +181 -0
  10. package/dist/main.js +19 -0
  11. package/dist/react-router.development.js +1397 -0
  12. package/dist/react-router.development.js.map +1 -0
  13. package/dist/react-router.production.min.js +12 -0
  14. package/dist/react-router.production.min.js.map +1 -0
  15. package/dist/umd/react-router.development.js +1624 -0
  16. package/dist/umd/react-router.development.js.map +1 -0
  17. package/dist/umd/react-router.production.min.js +12 -0
  18. package/dist/umd/react-router.production.min.js.map +1 -0
  19. package/package.json +9 -111
  20. package/dist/development/chunk-RMWJZNG5.mjs +0 -11505
  21. package/dist/development/data-CQbyyGzl.d.mts +0 -11
  22. package/dist/development/data-CQbyyGzl.d.ts +0 -11
  23. package/dist/development/dom-export.d.mts +0 -23
  24. package/dist/development/dom-export.d.ts +0 -23
  25. package/dist/development/dom-export.js +0 -6341
  26. package/dist/development/dom-export.mjs +0 -222
  27. package/dist/development/fog-of-war-C5L_Yd5M.d.mts +0 -1778
  28. package/dist/development/fog-of-war-DrUCUQQ-.d.ts +0 -1778
  29. package/dist/development/index.d.mts +0 -855
  30. package/dist/development/index.d.ts +0 -855
  31. package/dist/development/index.js +0 -11664
  32. package/dist/development/index.mjs +0 -263
  33. package/dist/development/lib/types/route-module.d.mts +0 -209
  34. package/dist/development/lib/types/route-module.d.ts +0 -209
  35. package/dist/development/lib/types/route-module.js +0 -28
  36. package/dist/development/lib/types/route-module.mjs +0 -10
  37. package/dist/development/route-data-BIYebJr3.d.mts +0 -1749
  38. package/dist/development/route-data-BIYebJr3.d.ts +0 -1749
  39. package/dist/development/rsc-export.d.mts +0 -1788
  40. package/dist/development/rsc-export.d.ts +0 -1788
  41. package/dist/development/rsc-export.js +0 -2778
  42. package/dist/development/rsc-export.mjs +0 -2743
  43. package/dist/production/chunk-BXBFRMFA.mjs +0 -11505
  44. package/dist/production/data-CQbyyGzl.d.mts +0 -11
  45. package/dist/production/data-CQbyyGzl.d.ts +0 -11
  46. package/dist/production/dom-export.d.mts +0 -23
  47. package/dist/production/dom-export.d.ts +0 -23
  48. package/dist/production/dom-export.js +0 -6341
  49. package/dist/production/dom-export.mjs +0 -222
  50. package/dist/production/fog-of-war-C5L_Yd5M.d.mts +0 -1778
  51. package/dist/production/fog-of-war-DrUCUQQ-.d.ts +0 -1778
  52. package/dist/production/index.d.mts +0 -855
  53. package/dist/production/index.d.ts +0 -855
  54. package/dist/production/index.js +0 -11664
  55. package/dist/production/index.mjs +0 -263
  56. package/dist/production/lib/types/route-module.d.mts +0 -209
  57. package/dist/production/lib/types/route-module.d.ts +0 -209
  58. package/dist/production/lib/types/route-module.js +0 -28
  59. package/dist/production/lib/types/route-module.mjs +0 -10
  60. package/dist/production/route-data-BIYebJr3.d.mts +0 -1749
  61. package/dist/production/route-data-BIYebJr3.d.ts +0 -1749
  62. package/dist/production/rsc-export.d.mts +0 -1788
  63. package/dist/production/rsc-export.d.ts +0 -1788
  64. package/dist/production/rsc-export.js +0 -2778
  65. package/dist/production/rsc-export.mjs +0 -2743
@@ -1,1778 +0,0 @@
1
- import * as React from 'react';
2
- import { p as StaticHandlerContext, c as RouteManifest, b as RouteModules, H as HydrationState, G as DataRouteObject, J as ClientLoaderFunction, k as RouteObject, R as RouterInit, F as FutureConfig$1, I as InitialEntry, D as DataStrategyFunction, at as PatchRoutesOnNavigationFunction, a as Router$1, T as To, d as RelativeRoutingType, y as NonIndexRouteObject, a5 as LazyRouteFunction, s as IndexRouteObject, e as Location, f as Action, as as Navigator, av as RouteMatch, a4 as HTMLFormMethod, a2 as FormEncType, aD as PageLinkDescriptor, aT as History, O as GetScrollRestorationKeyFunction, N as NavigateOptions, Q as Fetcher, n as SerializeFrom, B as BlockerFunction, aw as ClientActionFunction, x as LinksFunction, w as MetaFunction, aa as ShouldRevalidateFunction, j as Params } from './route-data-BIYebJr3.mjs';
3
-
4
- type SerializedError = {
5
- message: string;
6
- stack?: string;
7
- };
8
- interface FrameworkContextObject {
9
- manifest: AssetsManifest;
10
- routeModules: RouteModules;
11
- criticalCss?: CriticalCss;
12
- serverHandoffString?: string;
13
- future: FutureConfig;
14
- ssr: boolean;
15
- isSpaMode: boolean;
16
- serializeError?(error: Error): SerializedError;
17
- renderMeta?: {
18
- didRenderScripts?: boolean;
19
- streamCache?: Record<number, Promise<void> & {
20
- result?: {
21
- done: boolean;
22
- value: string;
23
- };
24
- error?: unknown;
25
- }>;
26
- };
27
- }
28
- interface EntryContext extends FrameworkContextObject {
29
- staticHandlerContext: StaticHandlerContext;
30
- serverHandoffStream?: ReadableStream<Uint8Array>;
31
- }
32
- interface FutureConfig {
33
- unstable_subResourceIntegrity: boolean;
34
- unstable_middleware: boolean;
35
- }
36
- type CriticalCss = string | {
37
- rel: "stylesheet";
38
- href: string;
39
- };
40
- interface AssetsManifest {
41
- entry: {
42
- imports: string[];
43
- module: string;
44
- };
45
- routes: RouteManifest<EntryRoute>;
46
- url: string;
47
- version: string;
48
- hmr?: {
49
- timestamp?: number;
50
- runtime: string;
51
- };
52
- sri?: Record<string, string> | true;
53
- }
54
-
55
- interface Route$1 {
56
- index?: boolean;
57
- caseSensitive?: boolean;
58
- id: string;
59
- parentId?: string;
60
- path?: string;
61
- }
62
- interface EntryRoute extends Route$1 {
63
- hasAction: boolean;
64
- hasLoader: boolean;
65
- hasClientAction: boolean;
66
- hasClientLoader: boolean;
67
- hasClientMiddleware: boolean;
68
- hasErrorBoundary: boolean;
69
- imports?: string[];
70
- css?: string[];
71
- module: string;
72
- clientActionModule: string | undefined;
73
- clientLoaderModule: string | undefined;
74
- clientMiddlewareModule: string | undefined;
75
- hydrateFallbackModule: string | undefined;
76
- parentId?: string;
77
- }
78
- declare function createClientRoutesWithHMRRevalidationOptOut(needsRevalidation: Set<string>, manifest: RouteManifest<EntryRoute>, routeModulesCache: RouteModules, initialState: HydrationState, ssr: boolean, isSpaMode: boolean): DataRouteObject[];
79
- declare function createClientRoutes(manifest: RouteManifest<EntryRoute>, routeModulesCache: RouteModules, initialState: HydrationState | null, ssr: boolean, isSpaMode: boolean, parentId?: string, routesByParentId?: Record<string, Omit<EntryRoute, "children">[]>, needsRevalidation?: Set<string>): DataRouteObject[];
80
- declare function shouldHydrateRouteLoader(routeId: string, clientLoader: ClientLoaderFunction | undefined, hasLoader: boolean, isSpaMode: boolean): boolean;
81
-
82
- /**
83
- * @private
84
- */
85
- declare function mapRouteProperties(route: RouteObject): Partial<RouteObject> & {
86
- hasErrorBoundary: boolean;
87
- };
88
- declare const hydrationRouteProperties: (keyof RouteObject)[];
89
- interface MemoryRouterOpts {
90
- /**
91
- * Basename path for the application.
92
- */
93
- basename?: string;
94
- /**
95
- * Function to provide the initial context values for all client side navigations/fetches
96
- */
97
- unstable_getContext?: RouterInit["unstable_getContext"];
98
- /**
99
- * Future flags to enable for the router.
100
- */
101
- future?: Partial<FutureConfig$1>;
102
- /**
103
- * Hydration data to initialize the router with if you have already performed
104
- * data loading on the server.
105
- */
106
- hydrationData?: HydrationState;
107
- /**
108
- * Initial entires in the in-memory history stack
109
- */
110
- initialEntries?: InitialEntry[];
111
- /**
112
- * Index of `initialEntries` the application should initialize to
113
- */
114
- initialIndex?: number;
115
- /**
116
- * Override the default data strategy of loading in parallel.
117
- * Only intended for advanced usage.
118
- */
119
- dataStrategy?: DataStrategyFunction;
120
- /**
121
- * Lazily define portions of the route tree on navigations.
122
- */
123
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
124
- }
125
- /**
126
- * Create a new data router that manages the application path using an in-memory
127
- * history stack. Useful for non-browser environments without a DOM API.
128
- *
129
- * @category Data Routers
130
- */
131
- declare function createMemoryRouter(
132
- /**
133
- * Application routes
134
- */
135
- routes: RouteObject[],
136
- /**
137
- * Router options
138
- */
139
- opts?: MemoryRouterOpts): Router$1;
140
- interface RouterProviderProps {
141
- router: Router$1;
142
- flushSync?: (fn: () => unknown) => undefined;
143
- }
144
- /**
145
- * Given a Remix Router instance, render the appropriate UI
146
- */
147
- declare function RouterProvider({ router, flushSync: reactDomFlushSyncImpl, }: RouterProviderProps): React.ReactElement;
148
- /**
149
- * @category Types
150
- */
151
- interface MemoryRouterProps {
152
- basename?: string;
153
- children?: React.ReactNode;
154
- initialEntries?: InitialEntry[];
155
- initialIndex?: number;
156
- }
157
- /**
158
- * A `<Router>` that stores all entries in memory.
159
- *
160
- * @category Component Routers
161
- */
162
- declare function MemoryRouter({ basename, children, initialEntries, initialIndex, }: MemoryRouterProps): React.ReactElement;
163
- /**
164
- * @category Types
165
- */
166
- interface NavigateProps {
167
- to: To;
168
- replace?: boolean;
169
- state?: any;
170
- relative?: RelativeRoutingType;
171
- }
172
- /**
173
- * A component-based version of {@link useNavigate} to use in a [`React.Component
174
- * Class`](https://reactjs.org/docs/react-component.html) where hooks are not
175
- * able to be used.
176
- *
177
- * It's recommended to avoid using this component in favor of {@link useNavigate}
178
- *
179
- * @category Components
180
- */
181
- declare function Navigate({ to, replace, state, relative, }: NavigateProps): null;
182
- /**
183
- * @category Types
184
- */
185
- interface OutletProps {
186
- /**
187
- Provides a context value to the element tree below the outlet. Use when the parent route needs to provide values to child routes.
188
-
189
- ```tsx
190
- <Outlet context={myContextValue} />
191
- ```
192
-
193
- Access the context with {@link useOutletContext}.
194
- */
195
- context?: unknown;
196
- }
197
- /**
198
- Renders the matching child route of a parent route or nothing if no child route matches.
199
-
200
- ```tsx
201
- import { Outlet } from "react-router"
202
-
203
- export default function SomeParent() {
204
- return (
205
- <div>
206
- <h1>Parent Content</h1>
207
- <Outlet />
208
- </div>
209
- );
210
- }
211
- ```
212
-
213
- @category Components
214
- */
215
- declare function Outlet(props: OutletProps): React.ReactElement | null;
216
- /**
217
- * @category Types
218
- */
219
- interface PathRouteProps {
220
- caseSensitive?: NonIndexRouteObject["caseSensitive"];
221
- path?: NonIndexRouteObject["path"];
222
- id?: NonIndexRouteObject["id"];
223
- lazy?: LazyRouteFunction<NonIndexRouteObject>;
224
- loader?: NonIndexRouteObject["loader"];
225
- action?: NonIndexRouteObject["action"];
226
- hasErrorBoundary?: NonIndexRouteObject["hasErrorBoundary"];
227
- shouldRevalidate?: NonIndexRouteObject["shouldRevalidate"];
228
- handle?: NonIndexRouteObject["handle"];
229
- index?: false;
230
- children?: React.ReactNode;
231
- element?: React.ReactNode | null;
232
- hydrateFallbackElement?: React.ReactNode | null;
233
- errorElement?: React.ReactNode | null;
234
- Component?: React.ComponentType | null;
235
- HydrateFallback?: React.ComponentType | null;
236
- ErrorBoundary?: React.ComponentType | null;
237
- }
238
- /**
239
- * @category Types
240
- */
241
- interface LayoutRouteProps extends PathRouteProps {
242
- }
243
- /**
244
- * @category Types
245
- */
246
- interface IndexRouteProps {
247
- caseSensitive?: IndexRouteObject["caseSensitive"];
248
- path?: IndexRouteObject["path"];
249
- id?: IndexRouteObject["id"];
250
- lazy?: LazyRouteFunction<IndexRouteObject>;
251
- loader?: IndexRouteObject["loader"];
252
- action?: IndexRouteObject["action"];
253
- hasErrorBoundary?: IndexRouteObject["hasErrorBoundary"];
254
- shouldRevalidate?: IndexRouteObject["shouldRevalidate"];
255
- handle?: IndexRouteObject["handle"];
256
- index: true;
257
- children?: undefined;
258
- element?: React.ReactNode | null;
259
- hydrateFallbackElement?: React.ReactNode | null;
260
- errorElement?: React.ReactNode | null;
261
- Component?: React.ComponentType | null;
262
- HydrateFallback?: React.ComponentType | null;
263
- ErrorBoundary?: React.ComponentType | null;
264
- }
265
- type RouteProps = PathRouteProps | LayoutRouteProps | IndexRouteProps;
266
- /**
267
- * Configures an element to render when a pattern matches the current location.
268
- * It must be rendered within a {@link Routes} element. Note that these routes
269
- * do not participate in data loading, actions, code splitting, or any other
270
- * route module features.
271
- *
272
- * @category Components
273
- */
274
- declare function Route(_props: RouteProps): React.ReactElement | null;
275
- /**
276
- * @category Types
277
- */
278
- interface RouterProps {
279
- basename?: string;
280
- children?: React.ReactNode;
281
- location: Partial<Location> | string;
282
- navigationType?: Action;
283
- navigator: Navigator;
284
- static?: boolean;
285
- }
286
- /**
287
- * Provides location context for the rest of the app.
288
- *
289
- * Note: You usually won't render a `<Router>` directly. Instead, you'll render a
290
- * router that is more specific to your environment such as a `<BrowserRouter>`
291
- * in web browsers or a `<StaticRouter>` for server rendering.
292
- *
293
- * @category Components
294
- */
295
- declare function Router({ basename: basenameProp, children, location: locationProp, navigationType, navigator, static: staticProp, }: RouterProps): React.ReactElement | null;
296
- /**
297
- * @category Types
298
- */
299
- interface RoutesProps {
300
- /**
301
- * Nested {@link Route} elements
302
- */
303
- children?: React.ReactNode;
304
- /**
305
- * The location to match against. Defaults to the current location.
306
- */
307
- location?: Partial<Location> | string;
308
- }
309
- /**
310
- Renders a branch of {@link Route | `<Routes>`} that best matches the current
311
- location. Note that these routes do not participate in data loading, actions,
312
- code splitting, or any other route module features.
313
-
314
- ```tsx
315
- import { Routes, Route } from "react-router"
316
-
317
- <Routes>
318
- <Route index element={<StepOne />} />
319
- <Route path="step-2" element={<StepTwo />} />
320
- <Route path="step-3" element={<StepThree />}>
321
- </Routes>
322
- ```
323
-
324
- @category Components
325
- */
326
- declare function Routes({ children, location, }: RoutesProps): React.ReactElement | null;
327
- interface AwaitResolveRenderFunction<Resolve = any> {
328
- (data: Awaited<Resolve>): React.ReactNode;
329
- }
330
- /**
331
- * @category Types
332
- */
333
- interface AwaitProps<Resolve> {
334
- /**
335
- When using a function, the resolved value is provided as the parameter.
336
-
337
- ```tsx [2]
338
- <Await resolve={reviewsPromise}>
339
- {(resolvedReviews) => <Reviews items={resolvedReviews} />}
340
- </Await>
341
- ```
342
-
343
- When using React elements, {@link useAsyncValue} will provide the
344
- resolved value:
345
-
346
- ```tsx [2]
347
- <Await resolve={reviewsPromise}>
348
- <Reviews />
349
- </Await>
350
-
351
- function Reviews() {
352
- const resolvedReviews = useAsyncValue()
353
- return <div>...</div>
354
- }
355
- ```
356
- */
357
- children: React.ReactNode | AwaitResolveRenderFunction<Resolve>;
358
- /**
359
- The error element renders instead of the children when the promise rejects.
360
-
361
- ```tsx
362
- <Await
363
- errorElement={<div>Oops</div>}
364
- resolve={reviewsPromise}
365
- >
366
- <Reviews />
367
- </Await>
368
- ```
369
-
370
- To provide a more contextual error, you can use the {@link useAsyncError} in a
371
- child component
372
-
373
- ```tsx
374
- <Await
375
- errorElement={<ReviewsError />}
376
- resolve={reviewsPromise}
377
- >
378
- <Reviews />
379
- </Await>
380
-
381
- function ReviewsError() {
382
- const error = useAsyncError()
383
- return <div>Error loading reviews: {error.message}</div>
384
- }
385
- ```
386
-
387
- If you do not provide an errorElement, the rejected value will bubble up to
388
- the nearest route-level {@link NonIndexRouteObject#ErrorBoundary | ErrorBoundary} and be accessible
389
- via {@link useRouteError} hook.
390
- */
391
- errorElement?: React.ReactNode;
392
- /**
393
- Takes a promise returned from a {@link LoaderFunction | loader} value to be resolved and rendered.
394
-
395
- ```jsx
396
- import { useLoaderData, Await } from "react-router"
397
-
398
- export async function loader() {
399
- let reviews = getReviews() // not awaited
400
- let book = await getBook()
401
- return {
402
- book,
403
- reviews, // this is a promise
404
- }
405
- }
406
-
407
- export default function Book() {
408
- const {
409
- book,
410
- reviews, // this is the same promise
411
- } = useLoaderData()
412
-
413
- return (
414
- <div>
415
- <h1>{book.title}</h1>
416
- <p>{book.description}</p>
417
- <React.Suspense fallback={<ReviewsSkeleton />}>
418
- <Await
419
- // and is the promise we pass to Await
420
- resolve={reviews}
421
- >
422
- <Reviews />
423
- </Await>
424
- </React.Suspense>
425
- </div>
426
- );
427
- }
428
- ```
429
- */
430
- resolve: Resolve;
431
- }
432
- /**
433
- Used to render promise values with automatic error handling.
434
-
435
- ```tsx
436
- import { Await, useLoaderData } from "react-router";
437
-
438
- export function loader() {
439
- // not awaited
440
- const reviews = getReviews()
441
- // awaited (blocks the transition)
442
- const book = await fetch("/api/book").then((res) => res.json())
443
- return { book, reviews }
444
- }
445
-
446
- function Book() {
447
- const { book, reviews } = useLoaderData();
448
- return (
449
- <div>
450
- <h1>{book.title}</h1>
451
- <p>{book.description}</p>
452
- <React.Suspense fallback={<ReviewsSkeleton />}>
453
- <Await
454
- resolve={reviews}
455
- errorElement={
456
- <div>Could not load reviews 😬</div>
457
- }
458
- children={(resolvedReviews) => (
459
- <Reviews items={resolvedReviews} />
460
- )}
461
- />
462
- </React.Suspense>
463
- </div>
464
- );
465
- }
466
- ```
467
-
468
- **Note:** `<Await>` expects to be rendered inside of a `<React.Suspense>`
469
-
470
- @category Components
471
-
472
- */
473
- declare function Await<Resolve>({ children, errorElement, resolve, }: AwaitProps<Resolve>): React.JSX.Element;
474
- declare function WithRouteComponentProps({ children, }: {
475
- children: React.ReactElement;
476
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
477
- declare function WithHydrateFallbackProps({ children, }: {
478
- children: React.ReactElement;
479
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
480
- declare function WithErrorBoundaryProps({ children, }: {
481
- children: React.ReactElement;
482
- }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
483
- /**
484
- * Creates a route config from a React "children" object, which is usually
485
- * either a `<Route>` element or an array of them. Used internally by
486
- * `<Routes>` to create a route config from its children.
487
- *
488
- * @category Utils
489
- */
490
- declare function createRoutesFromChildren(children: React.ReactNode, parentPath?: number[]): RouteObject[];
491
- /**
492
- * Create route objects from JSX elements instead of arrays of objects
493
- */
494
- declare let createRoutesFromElements: typeof createRoutesFromChildren;
495
- /**
496
- * Renders the result of `matchRoutes()` into a React element.
497
- *
498
- * @category Utils
499
- */
500
- declare function renderMatches(matches: RouteMatch[] | null): React.ReactElement | null;
501
-
502
- type ParamKeyValuePair = [string, string];
503
- type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
504
- /**
505
- Creates a URLSearchParams object using the given initializer.
506
-
507
- This is identical to `new URLSearchParams(init)` except it also
508
- supports arrays as values in the object form of the initializer
509
- instead of just strings. This is convenient when you need multiple
510
- values for a given key, but don't want to use an array initializer.
511
-
512
- For example, instead of:
513
-
514
- ```tsx
515
- let searchParams = new URLSearchParams([
516
- ['sort', 'name'],
517
- ['sort', 'price']
518
- ]);
519
- ```
520
- you can do:
521
-
522
- ```
523
- let searchParams = createSearchParams({
524
- sort: ['name', 'price']
525
- });
526
- ```
527
-
528
- @category Utils
529
- */
530
- declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
531
- type JsonObject = {
532
- [Key in string]: JsonValue;
533
- } & {
534
- [Key in string]?: JsonValue | undefined;
535
- };
536
- type JsonArray = JsonValue[] | readonly JsonValue[];
537
- type JsonPrimitive = string | number | boolean | null;
538
- type JsonValue = JsonPrimitive | JsonObject | JsonArray;
539
- type SubmitTarget = HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | JsonValue | null;
540
- /**
541
- * Submit options shared by both navigations and fetchers
542
- */
543
- interface SharedSubmitOptions {
544
- /**
545
- * The HTTP method used to submit the form. Overrides `<form method>`.
546
- * Defaults to "GET".
547
- */
548
- method?: HTMLFormMethod;
549
- /**
550
- * The action URL path used to submit the form. Overrides `<form action>`.
551
- * Defaults to the path of the current route.
552
- */
553
- action?: string;
554
- /**
555
- * The encoding used to submit the form. Overrides `<form encType>`.
556
- * Defaults to "application/x-www-form-urlencoded".
557
- */
558
- encType?: FormEncType;
559
- /**
560
- * Determines whether the form action is relative to the route hierarchy or
561
- * the pathname. Use this if you want to opt out of navigating the route
562
- * hierarchy and want to instead route based on /-delimited URL segments
563
- */
564
- relative?: RelativeRoutingType;
565
- /**
566
- * In browser-based environments, prevent resetting scroll after this
567
- * navigation when using the <ScrollRestoration> component
568
- */
569
- preventScrollReset?: boolean;
570
- /**
571
- * Enable flushSync for this submission's state updates
572
- */
573
- flushSync?: boolean;
574
- }
575
- /**
576
- * Submit options available to fetchers
577
- */
578
- interface FetcherSubmitOptions extends SharedSubmitOptions {
579
- }
580
- /**
581
- * Submit options available to navigations
582
- */
583
- interface SubmitOptions extends FetcherSubmitOptions {
584
- /**
585
- * Set `true` to replace the current entry in the browser's history stack
586
- * instead of creating a new one (i.e. stay on "the same page"). Defaults
587
- * to `false`.
588
- */
589
- replace?: boolean;
590
- /**
591
- * State object to add to the history stack entry for this navigation
592
- */
593
- state?: any;
594
- /**
595
- * Indicate a specific fetcherKey to use when using navigate=false
596
- */
597
- fetcherKey?: string;
598
- /**
599
- * navigate=false will use a fetcher instead of a navigation
600
- */
601
- navigate?: boolean;
602
- /**
603
- * Enable view transitions on this submission navigation
604
- */
605
- viewTransition?: boolean;
606
- }
607
-
608
- declare const FrameworkContext: React.Context<FrameworkContextObject | undefined>;
609
- /**
610
- * Defines the discovery behavior of the link:
611
- *
612
- * - "render" - default, discover the route when the link renders
613
- * - "none" - don't eagerly discover, only discover if the link is clicked
614
- */
615
- type DiscoverBehavior = "render" | "none";
616
- /**
617
- * Defines the prefetching behavior of the link:
618
- *
619
- * - "none": Never fetched
620
- * - "intent": Fetched when the user focuses or hovers the link
621
- * - "render": Fetched when the link is rendered
622
- * - "viewport": Fetched when the link is in the viewport
623
- */
624
- type PrefetchBehavior = "intent" | "render" | "none" | "viewport";
625
- /**
626
- Renders all of the `<link>` tags created by route module {@link LinksFunction} export. You should render it inside the `<head>` of your document.
627
-
628
- ```tsx
629
- import { Links } from "react-router";
630
-
631
- export default function Root() {
632
- return (
633
- <html>
634
- <head>
635
- <Links />
636
- </head>
637
- <body></body>
638
- </html>
639
- );
640
- }
641
- ```
642
-
643
- @category Components
644
- */
645
- declare function Links(): React.JSX.Element;
646
- /**
647
- Renders `<link rel=prefetch|modulepreload>` tags for modules and data of another page to enable an instant navigation to that page. {@link LinkProps.prefetch | `<Link prefetch>`} uses this internally, but you can render it to prefetch a page for any other reason.
648
-
649
- ```tsx
650
- import { PrefetchPageLinks } from "react-router"
651
-
652
- <PrefetchPageLinks page="/absolute/path" />
653
- ```
654
-
655
- For example, you may render one of this as the user types into a search field to prefetch search results before they click through to their selection.
656
-
657
- @category Components
658
- */
659
- declare function PrefetchPageLinks({ page, ...dataLinkProps }: PageLinkDescriptor): React.JSX.Element | null;
660
- /**
661
- Renders all the `<meta>` tags created by route module {@link MetaFunction} exports. You should render it inside the `<head>` of your HTML.
662
-
663
- ```tsx
664
- import { Meta } from "react-router";
665
-
666
- export default function Root() {
667
- return (
668
- <html>
669
- <head>
670
- <Meta />
671
- </head>
672
- </html>
673
- );
674
- }
675
- ```
676
-
677
- @category Components
678
- */
679
- declare function Meta(): React.JSX.Element;
680
- /**
681
- A couple common attributes:
682
-
683
- - `<Scripts crossOrigin>` for hosting your static assets on a different server than your app.
684
- - `<Scripts nonce>` to support a [content security policy for scripts](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src) with [nonce-sources](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources) for your `<script>` tags.
685
-
686
- You cannot pass through attributes such as `async`, `defer`, `src`, `type`, `noModule` because they are managed by React Router internally.
687
-
688
- @category Types
689
- */
690
- type ScriptsProps = Omit<React.HTMLProps<HTMLScriptElement>, "children" | "async" | "defer" | "src" | "type" | "noModule" | "dangerouslySetInnerHTML" | "suppressHydrationWarning">;
691
- /**
692
- Renders the client runtime of your app. It should be rendered inside the `<body>` of the document.
693
-
694
- ```tsx
695
- import { Scripts } from "react-router";
696
-
697
- export default function Root() {
698
- return (
699
- <html>
700
- <head />
701
- <body>
702
- <Scripts />
703
- </body>
704
- </html>
705
- );
706
- }
707
- ```
708
-
709
- If server rendering, you can omit `<Scripts/>` and the app will work as a traditional web app without JavaScript, relying solely on HTML and browser behaviors.
710
-
711
- @category Components
712
- */
713
- declare function Scripts(props: ScriptsProps): React.JSX.Element | null;
714
-
715
- declare global {
716
- const REACT_ROUTER_VERSION: string;
717
- }
718
- /**
719
- * @category Routers
720
- */
721
- interface DOMRouterOpts {
722
- /**
723
- * Basename path for the application.
724
- */
725
- basename?: string;
726
- /**
727
- * Function to provide the initial context values for all client side navigations/fetches
728
- */
729
- unstable_getContext?: RouterInit["unstable_getContext"];
730
- /**
731
- * Future flags to enable for the router.
732
- */
733
- future?: Partial<FutureConfig$1>;
734
- /**
735
- * Hydration data to initialize the router with if you have already performed
736
- * data loading on the server.
737
- */
738
- hydrationData?: HydrationState;
739
- /**
740
- * Override the default data strategy of loading in parallel.
741
- * Only intended for advanced usage.
742
- */
743
- dataStrategy?: DataStrategyFunction;
744
- /**
745
- * Lazily define portions of the route tree on navigations.
746
- */
747
- patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
748
- /**
749
- * Window object override - defaults to the global `window` instance.
750
- */
751
- window?: Window;
752
- }
753
- /**
754
- * Create a new data router that manages the application path via `history.pushState`
755
- * and `history.replaceState`.
756
- *
757
- * @category Data Routers
758
- */
759
- declare function createBrowserRouter(
760
- /**
761
- * Application routes
762
- */
763
- routes: RouteObject[],
764
- /**
765
- * Router options
766
- */
767
- opts?: DOMRouterOpts): Router$1;
768
- /**
769
- * Create a new data router that manages the application path via the URL hash
770
- *
771
- * @category Data Routers
772
- */
773
- declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): Router$1;
774
- /**
775
- * @category Types
776
- */
777
- interface BrowserRouterProps {
778
- basename?: string;
779
- children?: React.ReactNode;
780
- window?: Window;
781
- }
782
- /**
783
- * A `<Router>` for use in web browsers. Provides the cleanest URLs.
784
- *
785
- * @category Component Routers
786
- */
787
- declare function BrowserRouter({ basename, children, window, }: BrowserRouterProps): React.JSX.Element;
788
- /**
789
- * @category Types
790
- */
791
- interface HashRouterProps {
792
- basename?: string;
793
- children?: React.ReactNode;
794
- window?: Window;
795
- }
796
- /**
797
- * A `<Router>` for use in web browsers. Stores the location in the hash
798
- * portion of the URL so it is not sent to the server.
799
- *
800
- * @category Component Routers
801
- */
802
- declare function HashRouter({ basename, children, window }: HashRouterProps): React.JSX.Element;
803
- /**
804
- * @category Types
805
- */
806
- interface HistoryRouterProps {
807
- basename?: string;
808
- children?: React.ReactNode;
809
- history: History;
810
- }
811
- /**
812
- * A `<Router>` that accepts a pre-instantiated history object. It's important
813
- * to note that using your own history object is highly discouraged and may add
814
- * two versions of the history library to your bundles unless you use the same
815
- * version of the history library that React Router uses internally.
816
- *
817
- * @name unstable_HistoryRouter
818
- * @category Component Routers
819
- */
820
- declare function HistoryRouter({ basename, children, history, }: HistoryRouterProps): React.JSX.Element;
821
- declare namespace HistoryRouter {
822
- var displayName: string;
823
- }
824
- /**
825
- * @category Types
826
- */
827
- interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
828
- /**
829
- Defines the link discovery behavior
830
-
831
- ```tsx
832
- <Link /> // default ("render")
833
- <Link discover="render" />
834
- <Link discover="none" />
835
- ```
836
-
837
- - **render** - default, discover the route when the link renders
838
- - **none** - don't eagerly discover, only discover if the link is clicked
839
- */
840
- discover?: DiscoverBehavior;
841
- /**
842
- Defines the data and module prefetching behavior for the link.
843
-
844
- ```tsx
845
- <Link /> // default
846
- <Link prefetch="none" />
847
- <Link prefetch="intent" />
848
- <Link prefetch="render" />
849
- <Link prefetch="viewport" />
850
- ```
851
-
852
- - **none** - default, no prefetching
853
- - **intent** - prefetches when the user hovers or focuses the link
854
- - **render** - prefetches when the link renders
855
- - **viewport** - prefetches when the link is in the viewport, very useful for mobile
856
-
857
- Prefetching is done with HTML `<link rel="prefetch">` tags. They are inserted after the link.
858
-
859
- ```tsx
860
- <a href="..." />
861
- <a href="..." />
862
- <link rel="prefetch" /> // might conditionally render
863
- ```
864
-
865
- 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).
866
- */
867
- prefetch?: PrefetchBehavior;
868
- /**
869
- 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>`).
870
-
871
- ```tsx
872
- <Link to="/logout" reloadDocument />
873
- ```
874
- */
875
- reloadDocument?: boolean;
876
- /**
877
- Replaces the current entry in the history stack instead of pushing a new one onto it.
878
-
879
- ```tsx
880
- <Link replace />
881
- ```
882
-
883
- ```
884
- # with a history stack like this
885
- A -> B
886
-
887
- # normal link click pushes a new entry
888
- A -> B -> C
889
-
890
- # but with `replace`, B is replaced by C
891
- A -> C
892
- ```
893
- */
894
- replace?: boolean;
895
- /**
896
- Adds persistent client side routing state to the next location.
897
-
898
- ```tsx
899
- <Link to="/somewhere/else" state={{ some: "value" }} />
900
- ```
901
-
902
- The location state is accessed from the `location`.
903
-
904
- ```tsx
905
- function SomeComp() {
906
- const location = useLocation()
907
- location.state; // { some: "value" }
908
- }
909
- ```
910
-
911
- 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)
912
- */
913
- state?: any;
914
- /**
915
- 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.
916
-
917
- ```tsx
918
- <Link to="?tab=one" preventScrollReset />
919
- ```
920
- */
921
- preventScrollReset?: boolean;
922
- /**
923
- Defines the relative path behavior for the link.
924
-
925
- ```tsx
926
- <Link to=".." /> // default: "route"
927
- <Link relative="route" />
928
- <Link relative="path" />
929
- ```
930
-
931
- Consider a route hierarchy where a parent route pattern is "blog" and a child route pattern is "blog/:slug/edit".
932
-
933
- - **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".
934
- - **path** - relative to the path so `..` will only remove one URL segment up to "/blog/:slug"
935
- */
936
- relative?: RelativeRoutingType;
937
- /**
938
- Can be a string or a partial {@link Path}:
939
-
940
- ```tsx
941
- <Link to="/some/path" />
942
-
943
- <Link
944
- to={{
945
- pathname: "/some/path",
946
- search: "?query=string",
947
- hash: "#hash",
948
- }}
949
- />
950
- ```
951
- */
952
- to: To;
953
- /**
954
- Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API) for this navigation.
955
-
956
- ```jsx
957
- <Link to={to} viewTransition>
958
- Click me
959
- </Link>
960
- ```
961
-
962
- To apply specific styles for the transition, see {@link useViewTransitionState}
963
- */
964
- viewTransition?: boolean;
965
- }
966
- /**
967
- A progressively enhanced `<a href>` wrapper to enable navigation with client-side routing.
968
-
969
- ```tsx
970
- import { Link } from "react-router";
971
-
972
- <Link to="/dashboard">Dashboard</Link>;
973
-
974
- <Link
975
- to={{
976
- pathname: "/some/path",
977
- search: "?query=string",
978
- hash: "#hash",
979
- }}
980
- />
981
- ```
982
-
983
- @category Components
984
- */
985
- declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
986
- /**
987
- The object passed to {@link NavLink} `children`, `className`, and `style` prop callbacks to render and style the link based on its state.
988
-
989
- ```
990
- // className
991
- <NavLink
992
- to="/messages"
993
- className={({ isActive, isPending }) =>
994
- isPending ? "pending" : isActive ? "active" : ""
995
- }
996
- >
997
- Messages
998
- </NavLink>
999
-
1000
- // style
1001
- <NavLink
1002
- to="/messages"
1003
- style={({ isActive, isPending }) => {
1004
- return {
1005
- fontWeight: isActive ? "bold" : "",
1006
- color: isPending ? "red" : "black",
1007
- }
1008
- )}
1009
- />
1010
-
1011
- // children
1012
- <NavLink to="/tasks">
1013
- {({ isActive, isPending }) => (
1014
- <span className={isActive ? "active" : ""}>Tasks</span>
1015
- )}
1016
- </NavLink>
1017
- ```
1018
-
1019
- */
1020
- type NavLinkRenderProps = {
1021
- /**
1022
- * Indicates if the link's URL matches the current location.
1023
- */
1024
- isActive: boolean;
1025
- /**
1026
- * Indicates if the pending location matches the link's URL.
1027
- */
1028
- isPending: boolean;
1029
- /**
1030
- * Indicates if a view transition to the link's URL is in progress. See {@link useViewTransitionState}
1031
- */
1032
- isTransitioning: boolean;
1033
- };
1034
- /**
1035
- * @category Types
1036
- */
1037
- interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
1038
- /**
1039
- Can be regular React children or a function that receives an object with the active and pending states of the link.
1040
-
1041
- ```tsx
1042
- <NavLink to="/tasks">
1043
- {({ isActive }) => (
1044
- <span className={isActive ? "active" : ""}>Tasks</span>
1045
- )}
1046
- </NavLink>
1047
- ```
1048
- */
1049
- children?: React.ReactNode | ((props: NavLinkRenderProps) => React.ReactNode);
1050
- /**
1051
- Changes the matching logic to make it case-sensitive:
1052
-
1053
- | Link | URL | isActive |
1054
- | -------------------------------------------- | ------------- | -------- |
1055
- | `<NavLink to="/SpOnGe-bOB" />` | `/sponge-bob` | true |
1056
- | `<NavLink to="/SpOnGe-bOB" caseSensitive />` | `/sponge-bob` | false |
1057
- */
1058
- caseSensitive?: boolean;
1059
- /**
1060
- Classes are automatically applied to NavLink that correspond to {@link NavLinkRenderProps}.
1061
-
1062
- ```css
1063
- a.active { color: red; }
1064
- a.pending { color: blue; }
1065
- a.transitioning {
1066
- view-transition-name: my-transition;
1067
- }
1068
- ```
1069
- */
1070
- className?: string | ((props: NavLinkRenderProps) => string | undefined);
1071
- /**
1072
- 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.
1073
-
1074
- | Link | URL | isActive |
1075
- | ----------------------------- | ------------ | -------- |
1076
- | `<NavLink to="/tasks" />` | `/tasks` | true |
1077
- | `<NavLink to="/tasks" />` | `/tasks/123` | true |
1078
- | `<NavLink to="/tasks" end />` | `/tasks` | true |
1079
- | `<NavLink to="/tasks" end />` | `/tasks/123` | false |
1080
-
1081
- `<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.
1082
- */
1083
- end?: boolean;
1084
- style?: React.CSSProperties | ((props: NavLinkRenderProps) => React.CSSProperties | undefined);
1085
- }
1086
- /**
1087
- Wraps {@link Link | `<Link>`} with additional props for styling active and pending states.
1088
-
1089
- - Automatically applies classes to the link based on its active and pending states, see {@link NavLinkProps.className}.
1090
- - 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.
1091
-
1092
- ```tsx
1093
- import { NavLink } from "react-router"
1094
- <NavLink to="/message" />
1095
- ```
1096
-
1097
- States are available through the className, style, and children render props. See {@link NavLinkRenderProps}.
1098
-
1099
- ```tsx
1100
- <NavLink
1101
- to="/messages"
1102
- className={({ isActive, isPending }) =>
1103
- isPending ? "pending" : isActive ? "active" : ""
1104
- }
1105
- >
1106
- Messages
1107
- </NavLink>
1108
- ```
1109
-
1110
- @category Components
1111
- */
1112
- declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
1113
- /**
1114
- * Form props shared by navigations and fetchers
1115
- */
1116
- interface SharedFormProps extends React.FormHTMLAttributes<HTMLFormElement> {
1117
- /**
1118
- * The HTTP verb to use when the form is submitted. Supports "get", "post",
1119
- * "put", "delete", and "patch".
1120
- *
1121
- * Native `<form>` only supports `get` and `post`, avoid the other verbs if
1122
- * you'd like to support progressive enhancement
1123
- */
1124
- method?: HTMLFormMethod;
1125
- /**
1126
- * The encoding type to use for the form submission.
1127
- */
1128
- encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
1129
- /**
1130
- * The URL to submit the form data to. If `undefined`, this defaults to the closest route in context.
1131
- */
1132
- action?: string;
1133
- /**
1134
- * Determines whether the form action is relative to the route hierarchy or
1135
- * the pathname. Use this if you want to opt out of navigating the route
1136
- * hierarchy and want to instead route based on /-delimited URL segments
1137
- */
1138
- relative?: RelativeRoutingType;
1139
- /**
1140
- * Prevent the scroll position from resetting to the top of the viewport on
1141
- * completion of the navigation when using the <ScrollRestoration> component
1142
- */
1143
- preventScrollReset?: boolean;
1144
- /**
1145
- * A function to call when the form is submitted. If you call
1146
- * `event.preventDefault()` then this form will not do anything.
1147
- */
1148
- onSubmit?: React.FormEventHandler<HTMLFormElement>;
1149
- }
1150
- /**
1151
- * Form props available to fetchers
1152
- * @category Types
1153
- */
1154
- interface FetcherFormProps extends SharedFormProps {
1155
- }
1156
- /**
1157
- * Form props available to navigations
1158
- * @category Types
1159
- */
1160
- interface FormProps extends SharedFormProps {
1161
- discover?: DiscoverBehavior;
1162
- /**
1163
- * Indicates a specific fetcherKey to use when using `navigate={false}` so you
1164
- * can pick up the fetcher's state in a different component in a {@link
1165
- * useFetcher}.
1166
- */
1167
- fetcherKey?: string;
1168
- /**
1169
- * Skips the navigation and uses a {@link useFetcher | fetcher} internally
1170
- * when `false`. This is essentially a shorthand for `useFetcher()` +
1171
- * `<fetcher.Form>` where you don't care about the resulting data in this
1172
- * component.
1173
- */
1174
- navigate?: boolean;
1175
- /**
1176
- * Forces a full document navigation instead of client side routing + data
1177
- * fetch.
1178
- */
1179
- reloadDocument?: boolean;
1180
- /**
1181
- * Replaces the current entry in the browser history stack when the form
1182
- * navigates. Use this if you don't want the user to be able to click "back"
1183
- * to the page with the form on it.
1184
- */
1185
- replace?: boolean;
1186
- /**
1187
- * State object to add to the history stack entry for this navigation
1188
- */
1189
- state?: any;
1190
- /**
1191
- * Enables a [View
1192
- * Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
1193
- * for this navigation. To apply specific styles during the transition see
1194
- * {@link useViewTransitionState}.
1195
- */
1196
- viewTransition?: boolean;
1197
- }
1198
- /**
1199
-
1200
- 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.
1201
-
1202
- 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.
1203
-
1204
- 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].
1205
-
1206
- ```tsx
1207
- import { Form } from "react-router";
1208
-
1209
- function NewEvent() {
1210
- return (
1211
- <Form action="/events" method="post">
1212
- <input name="title" type="text" />
1213
- <input name="description" type="text" />
1214
- </Form>
1215
- )
1216
- }
1217
- ```
1218
-
1219
- @category Components
1220
- */
1221
- declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
1222
- type ScrollRestorationProps = ScriptsProps & {
1223
- /**
1224
- Defines the key used to restore scroll positions.
1225
-
1226
- ```tsx
1227
- <ScrollRestoration
1228
- getKey={(location, matches) => {
1229
- // default behavior
1230
- return location.key
1231
- }}
1232
- />
1233
- ```
1234
- */
1235
- getKey?: GetScrollRestorationKeyFunction;
1236
- storageKey?: string;
1237
- };
1238
- /**
1239
- Emulates the browser's scroll restoration on location changes. Apps should only render one of these, right before the {@link Scripts} component.
1240
-
1241
- ```tsx
1242
- import { ScrollRestoration } from "react-router";
1243
-
1244
- export default function Root() {
1245
- return (
1246
- <html>
1247
- <body>
1248
- <ScrollRestoration />
1249
- <Scripts />
1250
- </body>
1251
- </html>
1252
- );
1253
- }
1254
- ```
1255
-
1256
- 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.
1257
-
1258
- ```tsx
1259
- <ScrollRestoration nonce={cspNonce} />
1260
- ```
1261
-
1262
- @category Components
1263
- */
1264
- declare function ScrollRestoration({ getKey, storageKey, ...props }: ScrollRestorationProps): React.JSX.Element | null;
1265
- declare namespace ScrollRestoration {
1266
- var displayName: string;
1267
- }
1268
- /**
1269
- * Handles the click behavior for router `<Link>` components. This is useful if
1270
- * you need to create custom `<Link>` components with the same click behavior we
1271
- * use in our exported `<Link>`.
1272
- *
1273
- * @category Hooks
1274
- */
1275
- declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, preventScrollReset, relative, viewTransition, }?: {
1276
- target?: React.HTMLAttributeAnchorTarget;
1277
- replace?: boolean;
1278
- state?: any;
1279
- preventScrollReset?: boolean;
1280
- relative?: RelativeRoutingType;
1281
- viewTransition?: boolean;
1282
- }): (event: React.MouseEvent<E, MouseEvent>) => void;
1283
- /**
1284
- Returns a tuple of the current URL's {@link URLSearchParams} and a function to update them. Setting the search params causes a navigation.
1285
-
1286
- ```tsx
1287
- import { useSearchParams } from "react-router";
1288
-
1289
- export function SomeComponent() {
1290
- const [searchParams, setSearchParams] = useSearchParams();
1291
- // ...
1292
- }
1293
- ```
1294
-
1295
- @category Hooks
1296
- */
1297
- declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
1298
- /**
1299
- Sets new search params and causes a navigation when called.
1300
-
1301
- ```tsx
1302
- <button
1303
- onClick={() => {
1304
- const params = new URLSearchParams();
1305
- params.set("someKey", "someValue");
1306
- setSearchParams(params, {
1307
- preventScrollReset: true,
1308
- });
1309
- }}
1310
- />
1311
- ```
1312
-
1313
- It also supports a function for setting new search params.
1314
-
1315
- ```tsx
1316
- <button
1317
- onClick={() => {
1318
- setSearchParams((prev) => {
1319
- prev.set("someKey", "someValue");
1320
- return prev;
1321
- });
1322
- }}
1323
- />
1324
- ```
1325
- */
1326
- type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
1327
- /**
1328
- * Submits a HTML `<form>` to the server without reloading the page.
1329
- */
1330
- interface SubmitFunction {
1331
- (
1332
- /**
1333
- Can be multiple types of elements and objects
1334
-
1335
- **`HTMLFormElement`**
1336
-
1337
- ```tsx
1338
- <Form
1339
- onSubmit={(event) => {
1340
- submit(event.currentTarget);
1341
- }}
1342
- />
1343
- ```
1344
-
1345
- **`FormData`**
1346
-
1347
- ```tsx
1348
- const formData = new FormData();
1349
- formData.append("myKey", "myValue");
1350
- submit(formData, { method: "post" });
1351
- ```
1352
-
1353
- **Plain object that will be serialized as `FormData`**
1354
-
1355
- ```tsx
1356
- submit({ myKey: "myValue" }, { method: "post" });
1357
- ```
1358
-
1359
- **Plain object that will be serialized as JSON**
1360
-
1361
- ```tsx
1362
- submit(
1363
- { myKey: "myValue" },
1364
- { method: "post", encType: "application/json" }
1365
- );
1366
- ```
1367
- */
1368
- target: SubmitTarget,
1369
- /**
1370
- * Options that override the `<form>`'s own attributes. Required when
1371
- * submitting arbitrary data without a backing `<form>`.
1372
- */
1373
- options?: SubmitOptions): Promise<void>;
1374
- }
1375
- /**
1376
- * Submits a fetcher `<form>` to the server without reloading the page.
1377
- */
1378
- interface FetcherSubmitFunction {
1379
- (
1380
- /**
1381
- Can be multiple types of elements and objects
1382
-
1383
- **`HTMLFormElement`**
1384
-
1385
- ```tsx
1386
- <fetcher.Form
1387
- onSubmit={(event) => {
1388
- fetcher.submit(event.currentTarget);
1389
- }}
1390
- />
1391
- ```
1392
-
1393
- **`FormData`**
1394
-
1395
- ```tsx
1396
- const formData = new FormData();
1397
- formData.append("myKey", "myValue");
1398
- fetcher.submit(formData, { method: "post" });
1399
- ```
1400
-
1401
- **Plain object that will be serialized as `FormData`**
1402
-
1403
- ```tsx
1404
- fetcher.submit({ myKey: "myValue" }, { method: "post" });
1405
- ```
1406
-
1407
- **Plain object that will be serialized as JSON**
1408
-
1409
- ```tsx
1410
- fetcher.submit(
1411
- { myKey: "myValue" },
1412
- { method: "post", encType: "application/json" }
1413
- );
1414
- ```
1415
-
1416
- */
1417
- target: SubmitTarget, options?: FetcherSubmitOptions): Promise<void>;
1418
- }
1419
- /**
1420
- The imperative version of {@link Form | `<Form>`} that lets you submit a form from code instead of a user interaction.
1421
-
1422
- ```tsx
1423
- import { useSubmit } from "react-router";
1424
-
1425
- function SomeComponent() {
1426
- const submit = useSubmit();
1427
- return (
1428
- <Form
1429
- onChange={(event) => {
1430
- submit(event.currentTarget);
1431
- }}
1432
- />
1433
- );
1434
- }
1435
- ```
1436
-
1437
- @category Hooks
1438
- */
1439
- declare function useSubmit(): SubmitFunction;
1440
- /**
1441
- Resolves the URL to the closest route in the component hierarchy instead of the current URL of the app.
1442
-
1443
- This is used internally by {@link Form} resolve the action to the closest route, but can be used generically as well.
1444
-
1445
- ```tsx
1446
- import { useFormAction } from "react-router";
1447
-
1448
- function SomeComponent() {
1449
- // closest route URL
1450
- let action = useFormAction();
1451
-
1452
- // closest route URL + "destroy"
1453
- let destroyAction = useFormAction("destroy");
1454
- }
1455
- ```
1456
-
1457
- @category Hooks
1458
- */
1459
- declare function useFormAction(
1460
- /**
1461
- * The action to append to the closest route URL.
1462
- */
1463
- action?: string, { relative }?: {
1464
- relative?: RelativeRoutingType;
1465
- }): string;
1466
- /**
1467
- The return value of `useFetcher` that keeps track of the state of a fetcher.
1468
-
1469
- ```tsx
1470
- let fetcher = useFetcher();
1471
- ```
1472
- */
1473
- type FetcherWithComponents<TData> = Fetcher<TData> & {
1474
- /**
1475
- Just like {@link Form} except it doesn't cause a navigation.
1476
-
1477
- ```tsx
1478
- function SomeComponent() {
1479
- const fetcher = useFetcher()
1480
- return (
1481
- <fetcher.Form method="post" action="/some/route">
1482
- <input type="text" />
1483
- </fetcher.Form>
1484
- )
1485
- }
1486
- ```
1487
- */
1488
- Form: React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>;
1489
- /**
1490
- Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
1491
-
1492
- The `formData` can be multiple types:
1493
-
1494
- - [`FormData`][form_data] - A `FormData` instance.
1495
- - [`HTMLFormElement`][html_form_element] - A [`<form>`][form_element] DOM element.
1496
- - `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.
1497
-
1498
- 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.
1499
-
1500
- ```tsx
1501
- // Submit a FormData instance (GET request)
1502
- const formData = new FormData();
1503
- fetcher.submit(formData);
1504
-
1505
- // Submit the HTML form element
1506
- fetcher.submit(event.currentTarget.form, {
1507
- method: "POST",
1508
- });
1509
-
1510
- // Submit key/value JSON as a FormData instance
1511
- fetcher.submit(
1512
- { serialized: "values" },
1513
- { method: "POST" }
1514
- );
1515
-
1516
- // Submit raw JSON
1517
- fetcher.submit(
1518
- {
1519
- deeply: {
1520
- nested: {
1521
- json: "values",
1522
- },
1523
- },
1524
- },
1525
- {
1526
- method: "POST",
1527
- encType: "application/json",
1528
- }
1529
- );
1530
- ```
1531
- */
1532
- submit: FetcherSubmitFunction;
1533
- /**
1534
- 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.
1535
-
1536
- ```tsx
1537
- let fetcher = useFetcher()
1538
-
1539
- <input onChange={e => {
1540
- fetcher.load(`/search?q=${e.target.value}`)
1541
- }} />
1542
- ```
1543
- */
1544
- load: (href: string, opts?: {
1545
- /**
1546
- * Wraps the initial state update for this `fetcher.load` in a
1547
- * `ReactDOM.flushSync` call instead of the default `React.startTransition`.
1548
- * This allows you to perform synchronous DOM actions immediately after the
1549
- * update is flushed to the DOM.
1550
- */
1551
- flushSync?: boolean;
1552
- }) => Promise<void>;
1553
- };
1554
- /**
1555
- Useful for creating complex, dynamic user interfaces that require multiple, concurrent data interactions without causing a navigation.
1556
-
1557
- Fetchers track their own, independent state and can be used to load data, submit forms, and generally interact with loaders and actions.
1558
-
1559
- ```tsx
1560
- import { useFetcher } from "react-router"
1561
-
1562
- function SomeComponent() {
1563
- let fetcher = useFetcher()
1564
-
1565
- // states are available on the fetcher
1566
- fetcher.state // "idle" | "loading" | "submitting"
1567
- fetcher.data // the data returned from the action or loader
1568
-
1569
- // render a form
1570
- <fetcher.Form method="post" />
1571
-
1572
- // load data
1573
- fetcher.load("/some/route")
1574
-
1575
- // submit data
1576
- fetcher.submit(someFormRef, { method: "post" })
1577
- fetcher.submit(someData, {
1578
- method: "post",
1579
- encType: "application/json"
1580
- })
1581
- }
1582
- ```
1583
-
1584
- @category Hooks
1585
- */
1586
- declare function useFetcher<T = any>({ key, }?: {
1587
- /**
1588
- 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:
1589
-
1590
- ```tsx
1591
- function SomeComp() {
1592
- let fetcher = useFetcher({ key: "my-key" })
1593
- // ...
1594
- }
1595
-
1596
- // Somewhere else
1597
- function AnotherComp() {
1598
- // this will be the same fetcher, sharing the state across the app
1599
- let fetcher = useFetcher({ key: "my-key" });
1600
- // ...
1601
- }
1602
- ```
1603
- */
1604
- key?: string;
1605
- }): FetcherWithComponents<SerializeFrom<T>>;
1606
- /**
1607
- 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.
1608
-
1609
- ```tsx
1610
- import { useFetchers } from "react-router";
1611
-
1612
- function SomeComponent() {
1613
- const fetchers = useFetchers();
1614
- fetchers[0].formData; // FormData
1615
- fetchers[0].state; // etc.
1616
- // ...
1617
- }
1618
- ```
1619
-
1620
- @category Hooks
1621
- */
1622
- declare function useFetchers(): (Fetcher & {
1623
- key: string;
1624
- })[];
1625
- /**
1626
- * When rendered inside a RouterProvider, will restore scroll positions on navigations
1627
- */
1628
- declare function useScrollRestoration({ getKey, storageKey, }?: {
1629
- getKey?: GetScrollRestorationKeyFunction;
1630
- storageKey?: string;
1631
- }): void;
1632
- /**
1633
- * Setup a callback to be fired on the window's `beforeunload` event.
1634
- *
1635
- * @category Hooks
1636
- */
1637
- declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
1638
- capture?: boolean;
1639
- }): void;
1640
- /**
1641
- Wrapper around useBlocker to show a window.confirm prompt to users instead of building a custom UI with {@link useBlocker}.
1642
-
1643
- 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.
1644
-
1645
- ```tsx
1646
- function ImportantForm() {
1647
- let [value, setValue] = React.useState("");
1648
-
1649
- // Block navigating elsewhere when data has been entered into the input
1650
- unstable_usePrompt({
1651
- message: "Are you sure?",
1652
- when: ({ currentLocation, nextLocation }) =>
1653
- value !== "" &&
1654
- currentLocation.pathname !== nextLocation.pathname,
1655
- });
1656
-
1657
- return (
1658
- <Form method="post">
1659
- <label>
1660
- Enter some important data:
1661
- <input
1662
- name="data"
1663
- value={value}
1664
- onChange={(e) => setValue(e.target.value)}
1665
- />
1666
- </label>
1667
- <button type="submit">Save</button>
1668
- </Form>
1669
- );
1670
- }
1671
- ```
1672
-
1673
- @category Hooks
1674
- @name unstable_usePrompt
1675
- */
1676
- declare function usePrompt({ when, message, }: {
1677
- when: boolean | BlockerFunction;
1678
- message: string;
1679
- }): void;
1680
- /**
1681
- 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)
1682
-
1683
- @category Hooks
1684
- @name useViewTransitionState
1685
- */
1686
- declare function useViewTransitionState(to: To, opts?: {
1687
- relative?: RelativeRoutingType;
1688
- }): boolean;
1689
-
1690
- type RenderedRoute = {
1691
- clientAction?: ClientActionFunction;
1692
- clientLoader?: ClientLoaderFunction;
1693
- element?: React.ReactElement | false;
1694
- errorElement?: React.ReactElement;
1695
- handle?: any;
1696
- hasAction: boolean;
1697
- hasErrorBoundary: boolean;
1698
- hasLoader: boolean;
1699
- hydrateFallbackElement?: React.ReactElement;
1700
- id: string;
1701
- index?: boolean;
1702
- links?: LinksFunction;
1703
- meta?: MetaFunction;
1704
- parentId?: string;
1705
- path?: string;
1706
- shouldRevalidate?: ShouldRevalidateFunction;
1707
- };
1708
- type ServerRouteMatch = RenderedRoute & {
1709
- params: Params;
1710
- pathname: string;
1711
- pathnameBase: string;
1712
- };
1713
- type ServerRenderPayload = {
1714
- type: "render";
1715
- actionData: Record<string, any> | null;
1716
- basename?: string;
1717
- errors: Record<string, any> | null;
1718
- loaderData: Record<string, any>;
1719
- location: Location;
1720
- matches: ServerRouteMatch[];
1721
- patches?: RenderedRoute[];
1722
- nonce?: string;
1723
- };
1724
- type ServerManifestPayload = {
1725
- type: "manifest";
1726
- matches: RenderedRoute[];
1727
- patches: RenderedRoute[];
1728
- };
1729
- type ServerActionPayload = {
1730
- type: "action";
1731
- actionResult: Promise<unknown>;
1732
- rerender?: Promise<ServerRenderPayload | ServerRedirectPayload>;
1733
- };
1734
- type ServerRedirectPayload = {
1735
- type: "redirect";
1736
- status: number;
1737
- location: string;
1738
- replace: boolean;
1739
- reload: boolean;
1740
- };
1741
- type ServerPayload = ServerRenderPayload | ServerManifestPayload | ServerActionPayload | ServerRedirectPayload;
1742
-
1743
- type DecodeServerResponseFunction = (body: ReadableStream<Uint8Array>) => Promise<ServerPayload>;
1744
- type EncodeActionFunction = (args: unknown[]) => Promise<BodyInit>;
1745
- declare global {
1746
- interface Window {
1747
- __router: Router$1;
1748
- __routerInitialized: boolean;
1749
- __routerActionID: number;
1750
- }
1751
- }
1752
- declare function createCallServer({ decode, encodeAction, }: {
1753
- decode: DecodeServerResponseFunction;
1754
- encodeAction: EncodeActionFunction;
1755
- }): (id: string, args: unknown[]) => Promise<unknown>;
1756
- declare function RSCHydratedRouter({ decode, payload, }: {
1757
- decode: DecodeServerResponseFunction;
1758
- payload: ServerPayload;
1759
- }): React.JSX.Element;
1760
-
1761
- declare global {
1762
- interface Window {
1763
- __FLIGHT_DATA: any[];
1764
- }
1765
- }
1766
- declare function getServerStream(): ReadableStream<any>;
1767
-
1768
- declare global {
1769
- interface Navigator {
1770
- connection?: {
1771
- saveData: boolean;
1772
- };
1773
- }
1774
- }
1775
- declare function getPatchRoutesOnNavigationFunction(manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, isSpaMode: boolean, basename: string | undefined): PatchRoutesOnNavigationFunction | undefined;
1776
- declare function useFogOFWarDiscovery(router: Router$1, manifest: AssetsManifest, routeModules: RouteModules, ssr: boolean, isSpaMode: boolean): void;
1777
-
1778
- export { useLinkClickHandler as $, type AssetsManifest as A, type BrowserRouterProps as B, type CriticalCss as C, type DOMRouterOpts as D, type EntryContext as E, type FutureConfig as F, type SubmitFunction as G, type HashRouterProps as H, type IndexRouteProps as I, type FetcherSubmitFunction as J, type FetcherWithComponents as K, type LayoutRouteProps as L, type MemoryRouterOpts as M, type NavigateProps as N, type OutletProps as O, type PathRouteProps as P, createBrowserRouter as Q, type RouterProviderProps as R, type ServerPayload as S, createHashRouter as T, BrowserRouter as U, HashRouter as V, Link as W, HistoryRouter as X, NavLink as Y, Form as Z, ScrollRestoration as _, type Route$1 as a, useSearchParams as a0, useSubmit as a1, useFormAction as a2, useFetcher as a3, useFetchers as a4, useBeforeUnload as a5, usePrompt as a6, useViewTransitionState as a7, type FetcherSubmitOptions as a8, type ParamKeyValuePair as a9, type SubmitOptions as aa, type URLSearchParamsInit as ab, type SubmitTarget as ac, createSearchParams as ad, Meta as ae, Links as af, Scripts as ag, PrefetchPageLinks as ah, type ScriptsProps as ai, type DecodeServerResponseFunction as aj, type EncodeActionFunction as ak, createCallServer as al, RSCHydratedRouter as am, getServerStream as an, WithRouteComponentProps as ao, WithHydrateFallbackProps as ap, WithErrorBoundaryProps as aq, hydrationRouteProperties as ar, mapRouteProperties as as, FrameworkContext as at, getPatchRoutesOnNavigationFunction as au, useFogOFWarDiscovery as av, createClientRoutes as aw, createClientRoutesWithHMRRevalidationOptOut as ax, shouldHydrateRouteLoader as ay, useScrollRestoration as az, type AwaitProps as b, type MemoryRouterProps as c, type RouteProps as d, type RouterProps as e, type RoutesProps as f, Await as g, MemoryRouter as h, Navigate as i, Outlet as j, Route as k, Router as l, RouterProvider as m, Routes as n, createMemoryRouter as o, createRoutesFromChildren as p, createRoutesFromElements as q, renderMatches as r, type HistoryRouterProps as s, type LinkProps as t, type NavLinkProps as u, type NavLinkRenderProps as v, type FetcherFormProps as w, type FormProps as x, type ScrollRestorationProps as y, type SetURLSearchParams as z };