react-router 7.6.0 → 7.6.1-pre.0

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