INDIE UNPKG

74.4 kBTypeScriptView Raw
1
2import { History, To } from "../router/history.js";
3import { DataStrategyFunction, HTMLFormMethod, PatchRoutesOnNavigationFunction, RouteObject } from "../router/utils.js";
4import { BlockerFunction, Fetcher, FutureConfig, GetScrollRestorationKeyFunction, HydrationState, RelativeRoutingType, Router, RouterInit } from "../router/router.js";
5import { NavigateOptions } from "../context.js";
6import { SerializeFrom } from "../types/route-data.js";
7import { FetcherSubmitOptions, SubmitOptions, SubmitTarget, URLSearchParamsInit } from "./dom.js";
8import { DiscoverBehavior, PrefetchBehavior, ScriptsProps } from "./ssr/components.js";
9import { ClientInstrumentation } from "../router/instrumentation.js";
10import * as React$1 from "react";
11
12//#region lib/dom/lib.d.ts
13/**
14 * @category Data Routers
15 */
16interface DOMRouterOpts {
17 /**
18 * Basename path for the application.
19 */
20 basename?: string;
21 /**
22 * A function that returns an {@link RouterContextProvider} instance
23 * which is provided as the `context` argument to client [`action`](../../start/data/route-object#action)s,
24 * [`loader`](../../start/data/route-object#loader)s and [middleware](../../how-to/middleware).
25 * This function is called to generate a fresh `context` instance on each
26 * navigation or fetcher call.
27 *
28 * ```tsx
29 * import {
30 * createContext,
31 * RouterContextProvider,
32 * } from "react-router";
33 *
34 * const apiClientContext = createContext<APIClient>();
35 *
36 * function createBrowserRouter(routes, {
37 * getContext() {
38 * let context = new RouterContextProvider();
39 * context.set(apiClientContext, getApiClient());
40 * return context;
41 * }
42 * })
43 * ```
44 */
45 getContext?: RouterInit["getContext"];
46 /**
47 * Future flags to enable for the router.
48 */
49 future?: Partial<FutureConfig>;
50 /**
51 * When Server-Rendering and opting-out of automatic hydration, the
52 * `hydrationData` option allows you to pass in hydration data from your
53 * server-render. This will almost always be a subset of data from the
54 * {@link StaticHandlerContext} value you get back from the {@link StaticHandler}'s
55 * `query` method:
56 *
57 * ```tsx
58 * const router = createBrowserRouter(routes, {
59 * hydrationData: {
60 * loaderData: {
61 * // [routeId]: serverLoaderData
62 * },
63 * // may also include `errors` and/or `actionData`
64 * },
65 * });
66 * ```
67 *
68 * **Partial Hydration Data**
69 *
70 * You will almost always include a complete set of `loaderData` to hydrate a
71 * server-rendered app. But in advanced use-cases (such as Framework Mode's
72 * [`clientLoader`](../../start/framework/route-module#clientLoader)), you may
73 * want to include `loaderData` for only some routes that were loaded/rendered
74 * on the server. This allows you to hydrate _some_ of the routes (such as the
75 * app layout/shell) while showing a `HydrateFallback` component and running
76 * the [`loader`](../../start/data/route-object#loader)s for other routes
77 * during hydration.
78 *
79 * A route [`loader`](../../start/data/route-object#loader) will run during
80 * hydration in two scenarios:
81 *
82 * 1. No hydration data is provided
83 * In these cases the `HydrateFallback` component will render on initial
84 * hydration
85 * 2. The `loader.hydrate` property is set to `true`
86 * This allows you to run the [`loader`](../../start/data/route-object#loader)
87 * even if you did not render a fallback on initial hydration (i.e., to
88 * prime a cache with hydration data)
89 *
90 * ```tsx
91 * const router = createBrowserRouter(
92 * [
93 * {
94 * id: "root",
95 * loader: rootLoader,
96 * Component: Root,
97 * children: [
98 * {
99 * id: "index",
100 * loader: indexLoader,
101 * HydrateFallback: IndexSkeleton,
102 * Component: Index,
103 * },
104 * ],
105 * },
106 * ],
107 * {
108 * hydrationData: {
109 * loaderData: {
110 * root: "ROOT DATA",
111 * // No index data provided
112 * },
113 * },
114 * }
115 * );
116 * ```
117 */
118 hydrationData?: HydrationState;
119 /**
120 * Array of instrumentation objects allowing you to instrument the router and
121 * individual routes prior to router initialization (and on any subsequently
122 * added routes via `route.lazy` or `patchRoutesOnNavigation`). This is
123 * mostly useful for observability such as wrapping navigations, fetches,
124 * as well as route loaders/actions/middlewares with logging and/or performance
125 * tracing. See the [docs](../../how-to/instrumentation) for more information.
126 *
127 * ```tsx
128 * let router = createBrowserRouter(routes, {
129 * instrumentations: [logging]
130 * });
131 *
132 *
133 * let logging = {
134 * router({ instrument }) {
135 * instrument({
136 * navigate: (impl, info) => logExecution(`navigate ${info.to}`, impl),
137 * fetch: (impl, info) => logExecution(`fetch ${info.to}`, impl)
138 * });
139 * },
140 * route({ instrument, id }) {
141 * instrument({
142 * middleware: (impl, info) => logExecution(
143 * `middleware ${info.request.url} (route ${id})`,
144 * impl
145 * ),
146 * loader: (impl, info) => logExecution(
147 * `loader ${info.request.url} (route ${id})`,
148 * impl
149 * ),
150 * action: (impl, info) => logExecution(
151 * `action ${info.request.url} (route ${id})`,
152 * impl
153 * ),
154 * })
155 * }
156 * };
157 *
158 * async function logExecution(label: string, impl: () => Promise<void>) {
159 * let start = performance.now();
160 * console.log(`start ${label}`);
161 * await impl();
162 * let duration = Math.round(performance.now() - start);
163 * console.log(`end ${label} (${duration}ms)`);
164 * }
165 * ```
166 */
167 instrumentations?: ClientInstrumentation[];
168 /**
169 * Override the default data strategy of running loaders in parallel -
170 * see the [docs](../../how-to/data-strategy) for more information.
171 *
172 * ```tsx
173 * let router = createBrowserRouter(routes, {
174 * async dataStrategy({
175 * matches,
176 * request,
177 * runClientMiddleware,
178 * }) {
179 * const matchesToLoad = matches.filter((m) =>
180 * m.shouldCallHandler(),
181 * );
182 *
183 * const results: Record<string, DataStrategyResult> = {};
184 * await runClientMiddleware(() =>
185 * Promise.all(
186 * matchesToLoad.map(async (match) => {
187 * results[match.route.id] = await match.resolve();
188 * }),
189 * ),
190 * );
191 * return results;
192 * },
193 * });
194 * ```
195 */
196 dataStrategy?: DataStrategyFunction;
197 /**
198 * Lazily define portions of the route tree on navigations.
199 * See {@link PatchRoutesOnNavigationFunction}.
200 *
201 * By default, React Router wants you to provide a full route tree up front via
202 * `createBrowserRouter(routes)`. This allows React Router to perform synchronous
203 * route matching, execute loaders, and then render route components in the most
204 * optimistic manner without introducing waterfalls. The tradeoff is that your
205 * initial JS bundle is larger by definition — which may slow down application
206 * start-up times as your application grows.
207 *
208 * To combat this, we introduced [`route.lazy`](../../start/data/route-object#lazy)
209 * in [v6.9.0](https://github.com/remix-run/react-router/blob/main/CHANGELOG.md#v690)
210 * which lets you lazily load the route _implementation_ ([`loader`](../../start/data/route-object#loader),
211 * [`Component`](../../start/data/route-object#Component), etc.) while still
212 * providing the route _definition_ aspects up front (`path`, `index`, etc.).
213 * This is a good middle ground. React Router still knows about your route
214 * definitions (the lightweight part) up front and can perform synchronous
215 * route matching, but then delay loading any of the route implementation
216 * aspects (the heavier part) until the route is actually navigated to.
217 *
218 * In some cases, even this doesn't go far enough. For huge applications,
219 * providing all route definitions up front can be prohibitively expensive.
220 * Additionally, it might not even be possible to provide all route definitions
221 * up front in certain Micro-Frontend or Module-Federation architectures.
222 *
223 * This is where `patchRoutesOnNavigation` comes in ([RFC](https://github.com/remix-run/react-router/discussions/11113)).
224 * This API is for advanced use-cases where you are unable to provide the full
225 * route tree up-front and need a way to lazily "discover" portions of the route
226 * tree at runtime. This feature is often referred to as ["Fog of War"](https://en.wikipedia.org/wiki/Fog_of_war),
227 * because similar to how video games expand the "world" as you move around -
228 * the router would be expanding its routing tree as the user navigated around
229 * the app - but would only ever end up loading portions of the tree that the
230 * user visited.
231 *
232 * `patchRoutesOnNavigation` will be called anytime React Router is unable to
233 * match a `path`. The arguments include the `path`, any partial `matches`,
234 * and a `patch` function you can call to patch new routes into the tree at a
235 * specific location. This method is executed during the `loading` portion of
236 * the navigation for `GET` requests and during the `submitting` portion of
237 * the navigation for non-`GET` requests.
238 *
239 * <details>
240 * <summary><b>Example <code>patchRoutesOnNavigation</code> Use Cases</b></summary>
241 *
242 * **Patching children into an existing route**
243 *
244 * ```tsx
245 * const router = createBrowserRouter(
246 * [
247 * {
248 * id: "root",
249 * path: "/",
250 * Component: RootComponent,
251 * },
252 * ],
253 * {
254 * async patchRoutesOnNavigation({ patch, path }) {
255 * if (path === "/a") {
256 * // Load/patch the `a` route as a child of the route with id `root`
257 * let route = await getARoute();
258 * // ^ { path: 'a', Component: A }
259 * patch("root", [route]);
260 * }
261 * },
262 * }
263 * );
264 * ```
265 *
266 * In the above example, if the user clicks a link to `/a`, React Router
267 * won't match any routes initially and will call `patchRoutesOnNavigation`
268 * with a `path = "/a"` and a `matches` array containing the root route
269 * match. By calling `patch('root', [route])`, the new route will be added
270 * to the route tree as a child of the `root` route and React Router will
271 * perform matching on the updated routes. This time it will successfully
272 * match the `/a` path and the navigation will complete successfully.
273 *
274 * **Patching new root-level routes**
275 *
276 * If you need to patch a new route to the top of the tree (i.e., it doesn't
277 * have a parent), you can pass `null` as the `routeId`:
278 *
279 * ```tsx
280 * const router = createBrowserRouter(
281 * [
282 * {
283 * id: "root",
284 * path: "/",
285 * Component: RootComponent,
286 * },
287 * ],
288 * {
289 * async patchRoutesOnNavigation({ patch, path }) {
290 * if (path === "/root-sibling") {
291 * // Load/patch the `/root-sibling` route as a sibling of the root route
292 * let route = await getRootSiblingRoute();
293 * // ^ { path: '/root-sibling', Component: RootSibling }
294 * patch(null, [route]);
295 * }
296 * },
297 * }
298 * );
299 * ```
300 *
301 * **Patching subtrees asynchronously**
302 *
303 * You can also perform asynchronous matching to lazily fetch entire sections
304 * of your application:
305 *
306 * ```tsx
307 * let router = createBrowserRouter(
308 * [
309 * {
310 * path: "/",
311 * Component: Home,
312 * },
313 * ],
314 * {
315 * async patchRoutesOnNavigation({ patch, path }) {
316 * if (path.startsWith("/dashboard")) {
317 * let children = await import("./dashboard");
318 * patch(null, children);
319 * }
320 * if (path.startsWith("/account")) {
321 * let children = await import("./account");
322 * patch(null, children);
323 * }
324 * },
325 * }
326 * );
327 * ```
328 *
329 * <docs-info>If in-progress execution of `patchRoutesOnNavigation` is
330 * interrupted by a later navigation, then any remaining `patch` calls in
331 * the interrupted execution will not update the route tree because the
332 * operation was cancelled.</docs-info>
333 *
334 * **Co-locating route discovery with route definition**
335 *
336 * If you don't wish to perform your own pseudo-matching, you can leverage
337 * the partial `matches` array and the [`handle`](../../start/data/route-object#handle)
338 * field on a route to keep the children definitions co-located:
339 *
340 * ```tsx
341 * let router = createBrowserRouter(
342 * [
343 * {
344 * path: "/",
345 * Component: Home,
346 * },
347 * {
348 * path: "/dashboard",
349 * children: [
350 * {
351 * // If we want to include /dashboard in the critical routes, we need to
352 * // also include it's index route since patchRoutesOnNavigation will not be
353 * // called on a navigation to `/dashboard` because it will have successfully
354 * // matched the `/dashboard` parent route
355 * index: true,
356 * // ...
357 * },
358 * ],
359 * handle: {
360 * lazyChildren: () => import("./dashboard"),
361 * },
362 * },
363 * {
364 * path: "/account",
365 * children: [
366 * {
367 * index: true,
368 * // ...
369 * },
370 * ],
371 * handle: {
372 * lazyChildren: () => import("./account"),
373 * },
374 * },
375 * ],
376 * {
377 * async patchRoutesOnNavigation({ matches, patch }) {
378 * let leafRoute = matches[matches.length - 1]?.route;
379 * if (leafRoute?.handle?.lazyChildren) {
380 * let children =
381 * await leafRoute.handle.lazyChildren();
382 * patch(leafRoute.id, children);
383 * }
384 * },
385 * }
386 * );
387 * ```
388 *
389 * **A note on routes with parameters**
390 *
391 * Because React Router uses ranked routes to find the best match for a
392 * given path, there is an interesting ambiguity introduced when only a
393 * partial route tree is known at any given point in time. If we match a
394 * fully static route such as `path: "/about/contact-us"` then we know we've
395 * found the right match since it's composed entirely of static URL segments.
396 * Thus, we do not need to bother asking for any other potentially
397 * higher-scoring routes.
398 *
399 * However, routes with parameters (dynamic or splat) can't make this
400 * assumption because there might be a not-yet-discovered route that scores
401 * higher. Consider a full route tree such as:
402 *
403 * ```tsx
404 * // Assume this is the full route tree for your app
405 * const routes = [
406 * {
407 * path: "/",
408 * Component: Home,
409 * },
410 * {
411 * id: "blog",
412 * path: "/blog",
413 * Component: BlogLayout,
414 * children: [
415 * { path: "new", Component: NewPost },
416 * { path: ":slug", Component: BlogPost },
417 * ],
418 * },
419 * ];
420 * ```
421 *
422 * And then assume we want to use `patchRoutesOnNavigation` to fill this in
423 * as the user navigates around:
424 *
425 * ```tsx
426 * // Start with only the index route
427 * const router = createBrowserRouter(
428 * [
429 * {
430 * path: "/",
431 * Component: Home,
432 * },
433 * ],
434 * {
435 * async patchRoutesOnNavigation({ patch, path }) {
436 * if (path === "/blog/new") {
437 * patch("blog", [
438 * {
439 * path: "new",
440 * Component: NewPost,
441 * },
442 * ]);
443 * } else if (path.startsWith("/blog")) {
444 * patch("blog", [
445 * {
446 * path: ":slug",
447 * Component: BlogPost,
448 * },
449 * ]);
450 * }
451 * },
452 * }
453 * );
454 * ```
455 *
456 * If the user were to a blog post first (i.e., `/blog/my-post`) we would
457 * patch in the `:slug` route. Then, if the user navigated to `/blog/new` to
458 * write a new post, we'd match `/blog/:slug` but it wouldn't be the _right_
459 * match! We need to call `patchRoutesOnNavigation` just in case there
460 * exists a higher-scoring route we've not yet discovered, which in this
461 * case there is.
462 *
463 * So, anytime React Router matches a path that contains at least one param,
464 * it will call `patchRoutesOnNavigation` and match routes again just to
465 * confirm it has found the best match.
466 *
467 * If your `patchRoutesOnNavigation` implementation is expensive or making
468 * side effect [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch)
469 * calls to a backend server, you may want to consider tracking previously
470 * seen routes to avoid over-fetching in cases where you know the proper
471 * route has already been found. This can usually be as simple as
472 * maintaining a small cache of prior `path` values for which you've already
473 * patched in the right routes:
474 *
475 * ```tsx
476 * let discoveredRoutes = new Set();
477 *
478 * const router = createBrowserRouter(routes, {
479 * async patchRoutesOnNavigation({ patch, path }) {
480 * if (discoveredRoutes.has(path)) {
481 * // We've seen this before so nothing to patch in and we can let the router
482 * // use the routes it already knows about
483 * return;
484 * }
485 *
486 * discoveredRoutes.add(path);
487 *
488 * // ... patch routes in accordingly
489 * },
490 * });
491 * ```
492 * </details>
493 */
494 patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
495 /**
496 * [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
497 * override. Defaults to the global `window` instance.
498 */
499 window?: Window;
500}
501/**
502 * Create a new {@link DataRouter| data router} that manages the application
503 * path via [`history.pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState)
504 * and [`history.replaceState`](https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState).
505 *
506 * Data Routers should not be held in React state. You should create your router
507 * once outside of the React tree and pass it to {@link RouterProvider | `<RouterProvider>`}.
508 * You can use `patchRoutesOnNavigation` to add additional routes programmatically.
509 *
510 * @public
511 * @category Data Routers
512 * @mode data
513 * @param routes Application routes
514 * @param opts Options
515 * @param {DOMRouterOpts.basename} opts.basename n/a
516 * @param {DOMRouterOpts.dataStrategy} opts.dataStrategy n/a
517 * @param {DOMRouterOpts.future} opts.future n/a
518 * @param {DOMRouterOpts.getContext} opts.getContext n/a
519 * @param {DOMRouterOpts.hydrationData} opts.hydrationData n/a
520 * @param {DOMRouterOpts.instrumentations} opts.instrumentations n/a
521 * @param {DOMRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
522 * @param {DOMRouterOpts.window} opts.window n/a
523 * @returns An initialized {@link DataRouter| data router} to pass to {@link RouterProvider | `<RouterProvider>`}
524 */
525declare function createBrowserRouter(routes: RouteObject[], opts?: DOMRouterOpts): Router;
526/**
527 * Create a new {@link DataRouter| data router} that manages the application
528 * path via the URL [`hash`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hash).
529 *
530 * Data Routers should not be held in React state. You should create your router
531 * once outside of the React tree and pass it to {@link RouterProvider | `<RouterProvider>`}.
532 * You can use `patchRoutesOnNavigation` to add additional routes programmatically.
533 *
534 * @public
535 * @category Data Routers
536 * @mode data
537 * @param routes Application routes
538 * @param opts Options
539 * @param {DOMRouterOpts.basename} opts.basename n/a
540 * @param {DOMRouterOpts.future} opts.future n/a
541 * @param {DOMRouterOpts.getContext} opts.getContext n/a
542 * @param {DOMRouterOpts.hydrationData} opts.hydrationData n/a
543 * @param {DOMRouterOpts.instrumentations} opts.instrumentations n/a
544 * @param {DOMRouterOpts.dataStrategy} opts.dataStrategy n/a
545 * @param {DOMRouterOpts.patchRoutesOnNavigation} opts.patchRoutesOnNavigation n/a
546 * @param {DOMRouterOpts.window} opts.window n/a
547 * @returns An initialized {@link DataRouter| data router} to pass to {@link RouterProvider | `<RouterProvider>`}
548 */
549declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): Router;
550/**
551 * @category Types
552 */
553interface BrowserRouterProps {
554 /**
555 * Application basename
556 */
557 basename?: string;
558 /**
559 * {@link Route | `<Route>`} components describing your route configuration
560 */
561 children?: React$1.ReactNode;
562 /**
563 * Control whether router state updates are internally wrapped in
564 * [`React.startTransition`](https://react.dev/reference/react/startTransition).
565 *
566 * - When left `undefined`, all router state updates are wrapped in
567 * `React.startTransition`
568 * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
569 * in `React.startTransition` and all router state updates are wrapped in
570 * `React.startTransition`
571 * - When set to `false`, the router will not leverage `React.startTransition`
572 * on any navigations or state changes.
573 *
574 * For more information, please see the [docs](../../explanation/react-transitions).
575 */
576 useTransitions?: boolean;
577 /**
578 * [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
579 * override. Defaults to the global `window` instance
580 */
581 window?: Window;
582}
583/**
584 * A declarative {@link Router | `<Router>`} using the browser [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
585 * API for client-side routing.
586 *
587 * @public
588 * @category Declarative Routers
589 * @mode declarative
590 * @param props Props
591 * @param {BrowserRouterProps.basename} props.basename n/a
592 * @param {BrowserRouterProps.children} props.children n/a
593 * @param {BrowserRouterProps.useTransitions} props.useTransitions n/a
594 * @param {BrowserRouterProps.window} props.window n/a
595 * @returns A declarative {@link Router | `<Router>`} using the browser [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
596 * API for client-side routing.
597 */
598declare function BrowserRouter({
599 basename,
600 children,
601 useTransitions,
602 window
603}: BrowserRouterProps): React$1.JSX.Element;
604/**
605 * @category Types
606 */
607interface HashRouterProps {
608 /**
609 * Application basename
610 */
611 basename?: string;
612 /**
613 * {@link Route | `<Route>`} components describing your route configuration
614 */
615 children?: React$1.ReactNode;
616 /**
617 * Control whether router state updates are internally wrapped in
618 * [`React.startTransition`](https://react.dev/reference/react/startTransition).
619 *
620 * - When left `undefined`, all router state updates are wrapped in
621 * `React.startTransition`
622 * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
623 * in `React.startTransition` and all router state updates are wrapped in
624 * `React.startTransition`
625 * - When set to `false`, the router will not leverage `React.startTransition`
626 * on any navigations or state changes.
627 *
628 * For more information, please see the [docs](../../explanation/react-transitions).
629 */
630 useTransitions?: boolean;
631 /**
632 * [`Window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) object
633 * override. Defaults to the global `window` instance
634 */
635 window?: Window;
636}
637/**
638 * A declarative {@link Router | `<Router>`} that stores the location in the
639 * [`hash`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hash) portion
640 * of the URL so it is not sent to the server.
641 *
642 * @public
643 * @category Declarative Routers
644 * @mode declarative
645 * @param props Props
646 * @param {HashRouterProps.basename} props.basename n/a
647 * @param {HashRouterProps.children} props.children n/a
648 * @param {HashRouterProps.useTransitions} props.useTransitions n/a
649 * @param {HashRouterProps.window} props.window n/a
650 * @returns A declarative {@link Router | `<Router>`} using the URL [`hash`](https://developer.mozilla.org/en-US/docs/Web/API/URL/hash)
651 * for client-side routing.
652 */
653declare function HashRouter({
654 basename,
655 children,
656 useTransitions,
657 window
658}: HashRouterProps): React$1.JSX.Element;
659/**
660 * @category Types
661 */
662interface HistoryRouterProps {
663 /**
664 * Application basename
665 */
666 basename?: string;
667 /**
668 * {@link Route | `<Route>`} components describing your route configuration
669 */
670 children?: React$1.ReactNode;
671 /**
672 * A {@link History} implementation for use by the router
673 */
674 history: History;
675 /**
676 * Control whether router state updates are internally wrapped in
677 * [`React.startTransition`](https://react.dev/reference/react/startTransition).
678 *
679 * - When left `undefined`, all router state updates are wrapped in
680 * `React.startTransition`
681 * - When set to `true`, {@link Link} and {@link Form} navigations will be wrapped
682 * in `React.startTransition` and all router state updates are wrapped in
683 * `React.startTransition`
684 * - When set to `false`, the router will not leverage `React.startTransition`
685 * on any navigations or state changes.
686 *
687 * For more information, please see the [docs](../../explanation/react-transitions).
688 */
689 useTransitions?: boolean;
690}
691/**
692 * A declarative {@link Router | `<Router>`} that accepts a pre-instantiated
693 * `history` object.
694 * It's important to note that using your own `history` object is highly discouraged
695 * and may add two versions of the `history` library to your bundles unless you use
696 * the same version of the `history` library that React Router uses internally.
697 *
698 * @name unstable_HistoryRouter
699 * @public
700 * @category Declarative Routers
701 * @mode declarative
702 * @param props Props
703 * @param {HistoryRouterProps.basename} props.basename n/a
704 * @param {HistoryRouterProps.children} props.children n/a
705 * @param {HistoryRouterProps.history} props.history n/a
706 * @param {HistoryRouterProps.useTransitions} props.useTransitions n/a
707 * @returns A declarative {@link Router | `<Router>`} using the provided history
708 * implementation for client-side routing.
709 */
710declare function HistoryRouter({
711 basename,
712 children,
713 history,
714 useTransitions
715}: HistoryRouterProps): React$1.JSX.Element;
716declare namespace HistoryRouter {
717 var displayName: string;
718}
719/**
720 * @category Types
721 */
722interface LinkProps extends Omit<React$1.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
723 /**
724 * Defines the link [lazy route discovery](../../explanation/lazy-route-discovery) behavior.
725 *
726 * - **render** — default, discover the route when the link renders
727 * - **none** — don't eagerly discover, only discover if the link is clicked
728 *
729 * ```tsx
730 * <Link /> // default ("render")
731 * <Link discover="render" />
732 * <Link discover="none" />
733 * ```
734 */
735 discover?: DiscoverBehavior;
736 /**
737 * Defines the data and module prefetching behavior for the link.
738 *
739 * ```tsx
740 * <Link /> // default
741 * <Link prefetch="none" />
742 * <Link prefetch="intent" />
743 * <Link prefetch="render" />
744 * <Link prefetch="viewport" />
745 * ```
746 *
747 * - **none** — default, no prefetching
748 * - **intent** — prefetches when the user hovers or focuses the link
749 * - **render** — prefetches when the link renders
750 * - **viewport** — prefetches when the link is in the viewport, very useful for mobile
751 *
752 * Prefetching is done with HTML [`<link rel="prefetch">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
753 * tags. They are inserted after the link.
754 *
755 * ```tsx
756 * <a href="..." />
757 * <a href="..." />
758 * <link rel="prefetch" /> // might conditionally render
759 * ```
760 *
761 * Because of this, if you are using `nav :last-child` you will need to use
762 * `nav :last-of-type` so the styles don't conditionally fall off your last link
763 * (and any other similar selectors).
764 */
765 prefetch?: PrefetchBehavior;
766 /**
767 * Will use document navigation instead of client side routing when the link is
768 * clicked: the browser will handle the transition normally (as if it were an
769 * [`<a href>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a)).
770 *
771 * ```tsx
772 * <Link to="/logout" reloadDocument />
773 * ```
774 */
775 reloadDocument?: boolean;
776 /**
777 * Replaces the current entry in the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
778 * stack instead of pushing a new one onto it.
779 *
780 * ```tsx
781 * <Link replace />
782 * ```
783 *
784 * ```
785 * # with a history stack like this
786 * A -> B
787 *
788 * # normal link click pushes a new entry
789 * A -> B -> C
790 *
791 * # but with `replace`, B is replaced by C
792 * A -> C
793 * ```
794 */
795 replace?: boolean;
796 /**
797 * Adds persistent client side routing state to the next location.
798 *
799 * ```tsx
800 * <Link to="/somewhere/else" state={{ some: "value" }} />
801 * ```
802 *
803 * The location state is accessed from the `location`.
804 *
805 * ```tsx
806 * function SomeComp() {
807 * const location = useLocation();
808 * location.state; // { some: "value" }
809 * }
810 * ```
811 *
812 * This state is inaccessible on the server as it is implemented on top of
813 * [`history.state`](https://developer.mozilla.org/en-US/docs/Web/API/History/state)
814 */
815 state?: any;
816 /**
817 * Prevents the scroll position from being reset to the top of the window when
818 * the link is clicked and the app is using {@link ScrollRestoration}. This only
819 * prevents new locations resetting scroll to the top, scroll position will be
820 * restored for back/forward button navigation.
821 *
822 * ```tsx
823 * <Link to="?tab=one" preventScrollReset />
824 * ```
825 */
826 preventScrollReset?: boolean;
827 /**
828 * Defines the relative path behavior for the link.
829 *
830 * ```tsx
831 * <Link to=".." /> // default: "route"
832 * <Link relative="route" />
833 * <Link relative="path" />
834 * ```
835 *
836 * Consider a route hierarchy where a parent route pattern is `"blog"` and a child
837 * route pattern is `"blog/:slug/edit"`.
838 *
839 * - **route** — default, resolves the link relative to the route pattern. In the
840 * example above, a relative link of `"..."` will remove both `:slug/edit` segments
841 * back to `"/blog"`.
842 * - **path** — relative to the path so `"..."` will only remove one URL segment up
843 * to `"/blog/:slug"`
844 *
845 * Note that index routes and layout routes do not have paths so they are not
846 * included in the relative path calculation.
847 */
848 relative?: RelativeRoutingType;
849 /**
850 * Can be a string or a partial {@link Path}:
851 *
852 * ```tsx
853 * <Link to="/some/path" />
854 *
855 * <Link
856 * to={{
857 * pathname: "/some/path",
858 * search: "?query=string",
859 * hash: "#hash",
860 * }}
861 * />
862 * ```
863 */
864 to: To;
865 /**
866 * **Deprecated.** Use React's [`<ViewTransition>`](https://react.dev/reference/react/ViewTransition)
867 * component instead. See the [migration guide](../../how-to/view-transitions).
868 *
869 * Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
870 * for this navigation.
871 *
872 * ```jsx
873 * <Link to={to} viewTransition>
874 * Click me
875 * </Link>
876 * ```
877 *
878 * To apply specific styles for the transition, see {@link useViewTransitionState}
879 *
880 * @deprecated Use React's `<ViewTransition>` component instead.
881 */
882 viewTransition?: boolean;
883 /**
884 * Specify the default revalidation behavior for the navigation.
885 *
886 * ```tsx
887 * <Link to="/some/path" defaultShouldRevalidate={false} />
888 * ```
889 *
890 * If no `shouldRevalidate` functions are present on the active routes, then this
891 * value will be used directly. Otherwise it will be passed into `shouldRevalidate`
892 * so the route can make the final determination on revalidation. This can be
893 * useful when updating search params and you don't want to trigger a revalidation.
894 *
895 * By default (when not specified), loaders will revalidate according to the routers
896 * standard revalidation behavior.
897 */
898 defaultShouldRevalidate?: boolean;
899 /**
900 * Masked path for this navigation, when you want to navigate the router to
901 * one location but display a separate location in the URL bar.
902 *
903 * This is useful for contextual navigations such as opening an image in a modal
904 * on top of a gallery while keeping the underlying gallery active. If a user
905 * shares the masked URL, or opens the link in a new tab, they will only load
906 * the masked location without the underlying contextual location.
907 *
908 * This feature relies on `history.state` and is thus only intended for SPA uses
909 * and SSR renders will not respect the masking.
910 *
911 * ```tsx
912 * // routes/gallery.tsx
913 * export function clientLoader({ request }: Route.LoaderArgs) {
914 * let sp = new URL(request.url).searchParams;
915 * return {
916 * images: getImages(),
917 * modalImage: sp.has("image") ? getImage(sp.get("image")!) : null,
918 * };
919 * }
920 *
921 * export default function Gallery({ loaderData }: Route.ComponentProps) {
922 * return (
923 * <>
924 * <GalleryGrid>
925 * {loaderData.images.map((image) => (
926 * <Link
927 * key={image.id}
928 * to={`/gallery?image=${image.id}`}
929 * mask={`/images/${image.id}`}
930 * >
931 * <img src={image.url} alt={image.alt} />
932 * </Link>
933 * ))}
934 * </GalleryGrid>
935 *
936 * {data.modalImage ? (
937 * <dialog open>
938 * <img src={data.modalImage.url} alt={data.modalImage.alt} />
939 * </dialog>
940 * ) : null}
941 * </>
942 * );
943 * }
944 * ```
945 */
946 mask?: To;
947}
948/**
949 * A progressively enhanced [`<a href>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a)
950 * wrapper to enable navigation with client-side routing.
951 *
952 * @example
953 * import { Link } from "react-router";
954 *
955 * <Link to="/dashboard">Dashboard</Link>;
956 *
957 * <Link
958 * to={{
959 * pathname: "/some/path",
960 * search: "?query=string",
961 * hash: "#hash",
962 * }}
963 * />;
964 *
965 * @public
966 * @category Components
967 * @param {LinkProps.discover} props.discover [modes: framework] n/a
968 * @param {LinkProps.prefetch} props.prefetch [modes: framework] n/a
969 * @param {LinkProps.preventScrollReset} props.preventScrollReset [modes: framework, data] n/a
970 * @param {LinkProps.relative} props.relative n/a
971 * @param {LinkProps.reloadDocument} props.reloadDocument n/a
972 * @param {LinkProps.replace} props.replace n/a
973 * @param {LinkProps.state} props.state n/a
974 * @param {LinkProps.to} props.to n/a
975 * @param {LinkProps.viewTransition} props.viewTransition [modes: framework, data] n/a
976 * @param {LinkProps.defaultShouldRevalidate} props.defaultShouldRevalidate n/a
977 * @param {LinkProps.mask} props.mask [modes: framework, data] n/a
978 */
979declare const Link: React$1.ForwardRefExoticComponent<LinkProps & React$1.RefAttributes<HTMLAnchorElement>>;
980/**
981 * The object passed to {@link NavLink} `children`, `className`, and `style` prop
982 * callbacks to render and style the link based on its state.
983 *
984 * ```
985 * // className
986 * <NavLink
987 * to="/messages"
988 * className={({ isActive, isPending }) =>
989 * isPending ? "pending" : isActive ? "active" : ""
990 * }
991 * >
992 * Messages
993 * </NavLink>
994 *
995 * // style
996 * <NavLink
997 * to="/messages"
998 * style={({ isActive, isPending }) => {
999 * return {
1000 * fontWeight: isActive ? "bold" : "",
1001 * color: isPending ? "red" : "black",
1002 * }
1003 * )}
1004 * />
1005 *
1006 * // children
1007 * <NavLink to="/tasks">
1008 * {({ isActive, isPending }) => (
1009 * <span className={isActive ? "active" : ""}>Tasks</span>
1010 * )}
1011 * </NavLink>
1012 * ```
1013 *
1014 */
1015type NavLinkRenderProps = {
1016 /**
1017 * Indicates if the link's URL matches the current {@link Location}.
1018 */
1019 isActive: boolean;
1020 /**
1021 * Indicates if the pending {@link Location} matches the link's URL. Only
1022 * available in Framework/Data modes.
1023 */
1024 isPending: boolean;
1025 /**
1026 * Indicates if a view transition to the link's URL is in progress.
1027 * See {@link useViewTransitionState}
1028 *
1029 * @deprecated Only tracks React Router's deprecated view transitions. Use
1030 * React's `<ViewTransition>` component to style transitions instead. See the
1031 * [migration guide](https://reactrouter.com/how-to/view-transitions).
1032 */
1033 isTransitioning: boolean;
1034};
1035/**
1036 * @category Types
1037 */
1038interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
1039 /**
1040 * Can be regular React children or a function that receives an object with the
1041 * `active` and `pending` states of the link.
1042 *
1043 * ```tsx
1044 * <NavLink to="/tasks">
1045 * {({ isActive }) => (
1046 * <span className={isActive ? "active" : ""}>Tasks</span>
1047 * )}
1048 * </NavLink>
1049 * ```
1050 */
1051 children?: React$1.ReactNode | ((props: NavLinkRenderProps) => React$1.ReactNode);
1052 /**
1053 * Changes the matching logic to make it case-sensitive:
1054 *
1055 * | Link | URL | isActive |
1056 * | -------------------------------------------- | ------------- | -------- |
1057 * | `<NavLink to="/SpOnGe-bOB" />` | `/sponge-bob` | true |
1058 * | `<NavLink to="/SpOnGe-bOB" caseSensitive />` | `/sponge-bob` | false |
1059 */
1060 caseSensitive?: boolean;
1061 /**
1062 * Classes are automatically applied to `NavLink` that correspond to the state.
1063 *
1064 * ```css
1065 * a.active {
1066 * color: red;
1067 * }
1068 * a.pending {
1069 * color: blue;
1070 * }
1071 * ```
1072 *
1073 * Or you can specify a function that receives {@link NavLinkRenderProps} and
1074 * returns the `className`:
1075 *
1076 * ```tsx
1077 * <NavLink className={({ isActive, isPending }) => (
1078 * isActive ? "my-active-class" :
1079 * isPending ? "my-pending-class" :
1080 * ""
1081 * )} />
1082 * ```
1083 *
1084 * The `transitioning` class is deprecated and only tracks React Router's
1085 * legacy view transitions. Use React's [`<ViewTransition>`](https://react.dev/reference/react/ViewTransition)
1086 * component instead. See the [migration guide](../../how-to/view-transitions).
1087 */
1088 className?: string | ((props: NavLinkRenderProps) => string | undefined);
1089 /**
1090 * Changes the matching logic for the `active` and `pending` states to only match
1091 * to the "end" of the {@link NavLinkProps.to}. If the URL is longer, it will no
1092 * longer be considered active.
1093 *
1094 * | Link | URL | isActive |
1095 * | ----------------------------- | ------------ | -------- |
1096 * | `<NavLink to="/tasks" />` | `/tasks` | true |
1097 * | `<NavLink to="/tasks" />` | `/tasks/123` | true |
1098 * | `<NavLink to="/tasks" end />` | `/tasks` | true |
1099 * | `<NavLink to="/tasks" end />` | `/tasks/123` | false |
1100 *
1101 * `<NavLink to="/">` is an exceptional case because _every_ URL matches `/`.
1102 * To avoid this matching every single route by default, it effectively ignores
1103 * the `end` prop and only matches when you're at the root route.
1104 */
1105 end?: boolean;
1106 /**
1107 * Styles can also be applied dynamically via a function that receives
1108 * {@link NavLinkRenderProps} and returns the styles:
1109 *
1110 * ```tsx
1111 * <NavLink to="/tasks" style={{ color: "red" }} />
1112 * <NavLink to="/tasks" style={({ isActive, isPending }) => ({
1113 * color:
1114 * isActive ? "red" :
1115 * isPending ? "blue" : "black"
1116 * })} />
1117 * ```
1118 */
1119 style?: React$1.CSSProperties | ((props: NavLinkRenderProps) => React$1.CSSProperties | undefined);
1120}
1121/**
1122 * Wraps {@link Link | `<Link>`} with additional props for styling active and
1123 * pending states.
1124 *
1125 * - Automatically applies classes to the link based on its `active` and `pending`
1126 * states, see {@link NavLinkProps.className}
1127 * - Note that `pending` is only available with Framework and Data modes.
1128 * - Automatically applies `aria-current="page"` to the link when the link is active.
1129 * See [`aria-current`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current)
1130 * on MDN.
1131 * - States are additionally available through the className, style, and children
1132 * render props. See {@link NavLinkRenderProps}.
1133 *
1134 * @example
1135 * <NavLink to="/message">Messages</NavLink>
1136 *
1137 * // Using render props
1138 * <NavLink
1139 * to="/messages"
1140 * className={({ isActive, isPending }) =>
1141 * isPending ? "pending" : isActive ? "active" : ""
1142 * }
1143 * >
1144 * Messages
1145 * </NavLink>
1146 *
1147 * @public
1148 * @category Components
1149 * @param {NavLinkProps.caseSensitive} props.caseSensitive n/a
1150 * @param {NavLinkProps.children} props.children n/a
1151 * @param {NavLinkProps.className} props.className n/a
1152 * @param {NavLinkProps.discover} props.discover [modes: framework] n/a
1153 * @param {NavLinkProps.end} props.end n/a
1154 * @param {NavLinkProps.prefetch} props.prefetch [modes: framework] n/a
1155 * @param {NavLinkProps.preventScrollReset} props.preventScrollReset [modes: framework, data] n/a
1156 * @param {NavLinkProps.relative} props.relative n/a
1157 * @param {NavLinkProps.reloadDocument} props.reloadDocument n/a
1158 * @param {NavLinkProps.replace} props.replace n/a
1159 * @param {NavLinkProps.state} props.state n/a
1160 * @param {NavLinkProps.style} props.style n/a
1161 * @param {NavLinkProps.to} props.to n/a
1162 * @param {NavLinkProps.viewTransition} props.viewTransition [modes: framework, data] n/a
1163 */
1164declare const NavLink: React$1.ForwardRefExoticComponent<NavLinkProps & React$1.RefAttributes<HTMLAnchorElement>>;
1165/**
1166 * Form props shared by navigations and fetchers
1167 */
1168interface SharedFormProps extends React$1.FormHTMLAttributes<HTMLFormElement> {
1169 /**
1170 * The HTTP verb to use when the form is submitted. Supports `"delete"`,
1171 * `"get"`, `"patch"`, `"post"`, and `"put"`.
1172 *
1173 * Native [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
1174 * only supports `"get"` and `"post"`, avoid the other verbs if you'd like to
1175 * support progressive enhancement
1176 */
1177 method?: HTMLFormMethod;
1178 /**
1179 * The encoding type to use for the form submission.
1180 *
1181 * ```tsx
1182 * <Form encType="application/x-www-form-urlencoded"/> // Default
1183 * <Form encType="multipart/form-data"/>
1184 * <Form encType="text/plain"/>
1185 * ```
1186 */
1187 encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
1188 /**
1189 * The URL to submit the form data to. If `undefined`, this defaults to the
1190 * closest route in context.
1191 */
1192 action?: string;
1193 /**
1194 * Determines whether the form action is relative to the route hierarchy or
1195 * the pathname. Use this if you want to opt out of navigating the route
1196 * hierarchy and want to instead route based on slash-delimited URL segments.
1197 * See {@link RelativeRoutingType}.
1198 */
1199 relative?: RelativeRoutingType;
1200 /**
1201 * Prevent the scroll position from resetting to the top of the viewport on
1202 * completion of the navigation when using the
1203 * {@link ScrollRestoration | `<ScrollRestoration>`} component
1204 */
1205 preventScrollReset?: boolean;
1206 /**
1207 * Specify the default revalidation behavior after this submission
1208 *
1209 * If no `shouldRevalidate` functions are present on the active routes, then this
1210 * value will be used directly. Otherwise it will be passed into `shouldRevalidate`
1211 * so the route can make the final determination on revalidation. This can be
1212 * useful when updating search params and you don't want to trigger a revalidation.
1213 *
1214 * By default (when not specified), loaders will revalidate according to the routers
1215 * standard revalidation behavior.
1216 */
1217 defaultShouldRevalidate?: boolean;
1218}
1219/**
1220 * Form props available to fetchers
1221 * @category Types
1222 */
1223interface FetcherFormProps extends SharedFormProps {}
1224/**
1225 * Form props available to navigations
1226 * @category Types
1227 */
1228interface FormProps extends SharedFormProps {
1229 /**
1230 * Defines the form [lazy route discovery](../../explanation/lazy-route-discovery) behavior.
1231 *
1232 * - **render** — default, discover the route when the form renders
1233 * - **none** — don't eagerly discover, only discover if the form is submitted
1234 *
1235 * ```tsx
1236 * <Form /> // default ("render")
1237 * <Form discover="render" />
1238 * <Form discover="none" />
1239 * ```
1240 */
1241 discover?: DiscoverBehavior;
1242 /**
1243 * Indicates a specific fetcherKey to use when using `navigate={false}` so you
1244 * can pick up the fetcher's state in a different component in a {@link useFetcher}.
1245 */
1246 fetcherKey?: string;
1247 /**
1248 * When `false`, skips the navigation and submits via a fetcher internally.
1249 * This is essentially a shorthand for {@link useFetcher} + `<fetcher.Form>` where
1250 * you don't care about the resulting data in this component.
1251 */
1252 navigate?: boolean;
1253 /**
1254 * Forces a full document navigation instead of client side routing and data
1255 * fetch.
1256 */
1257 reloadDocument?: boolean;
1258 /**
1259 * Replaces the current entry in the browser [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1260 * stack when the form navigates. Use this if you don't want the user to be
1261 * able to click "back" to the page with the form on it.
1262 */
1263 replace?: boolean;
1264 /**
1265 * State object to add to the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1266 * stack entry for this navigation
1267 */
1268 state?: any;
1269 /**
1270 * **Deprecated.** Use React's [`<ViewTransition>`](https://react.dev/reference/react/ViewTransition)
1271 * component instead. See the [migration guide](../../how-to/view-transitions).
1272 *
1273 * Enables a [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
1274 * for this navigation. To apply specific styles during the transition, see
1275 * {@link useViewTransitionState}.
1276 *
1277 * @deprecated Use React's `<ViewTransition>` component instead.
1278 */
1279 viewTransition?: boolean;
1280}
1281/**
1282 * A progressively enhanced HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
1283 * that submits data to actions via [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch),
1284 * activating pending states in {@link useNavigation} which enables advanced
1285 * user interfaces beyond a basic HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form).
1286 * After a form's `action` completes, all data on the page is automatically
1287 * revalidated to keep the UI in sync with the data.
1288 *
1289 * Because it uses the HTML form API, server rendered pages are interactive at a
1290 * basic level before JavaScript loads. Instead of React Router managing the
1291 * submission, the browser manages the submission as well as the pending states
1292 * (like the spinning favicon). After JavaScript loads, React Router takes over
1293 * enabling web application user experiences.
1294 *
1295 * `Form` is most useful for submissions that should also change the URL or
1296 * otherwise add an entry to the browser history stack. For forms that shouldn't
1297 * manipulate the browser [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1298 * stack, use {@link FetcherWithComponents.Form | `<fetcher.Form>`}.
1299 *
1300 * @example
1301 * import { Form } from "react-router";
1302 *
1303 * function NewEvent() {
1304 * return (
1305 * <Form action="/events" method="post">
1306 * <input name="title" type="text" />
1307 * <input name="description" type="text" />
1308 * </Form>
1309 * );
1310 * }
1311 *
1312 * @public
1313 * @category Components
1314 * @mode framework
1315 * @mode data
1316 * @param {FormProps.action} action n/a
1317 * @param {FormProps.discover} discover n/a
1318 * @param {FormProps.encType} encType n/a
1319 * @param {FormProps.fetcherKey} fetcherKey n/a
1320 * @param {FormProps.method} method n/a
1321 * @param {FormProps.navigate} navigate n/a
1322 * @param {FormProps.preventScrollReset} preventScrollReset n/a
1323 * @param {FormProps.relative} relative n/a
1324 * @param {FormProps.reloadDocument} reloadDocument n/a
1325 * @param {FormProps.replace} replace n/a
1326 * @param {FormProps.state} state n/a
1327 * @param {FormProps.viewTransition} viewTransition n/a
1328 * @param {FormProps.defaultShouldRevalidate} defaultShouldRevalidate n/a
1329 * @returns A progressively enhanced [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) component
1330 */
1331declare const Form: React$1.ForwardRefExoticComponent<FormProps & React$1.RefAttributes<HTMLFormElement>>;
1332type ScrollRestorationProps = ScriptsProps & {
1333 /**
1334 * A function that returns a key to use for scroll restoration. This is useful
1335 * for custom scroll restoration logic, such as using only the pathname so
1336 * that later navigations to prior paths will restore the scroll. Defaults to
1337 * `location.key`. See {@link GetScrollRestorationKeyFunction}.
1338 *
1339 * ```tsx
1340 * <ScrollRestoration
1341 * getKey={(location, matches) => {
1342 * // Restore based on a unique location key (default behavior)
1343 * return location.key
1344 *
1345 * // Restore based on pathname
1346 * return location.pathname
1347 * }}
1348 * />
1349 * ```
1350 */
1351 getKey?: GetScrollRestorationKeyFunction;
1352 /**
1353 * The key to use for storing scroll positions in [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage).
1354 * Defaults to `"react-router-scroll-positions"`.
1355 */
1356 storageKey?: string;
1357};
1358/**
1359 * Emulates the browser's scroll restoration on location changes. Apps should only render one of these, right before the {@link Scripts} component.
1360 *
1361 * ```tsx
1362 * import { ScrollRestoration } from "react-router";
1363 *
1364 * export default function Root() {
1365 * return (
1366 * <html>
1367 * <body>
1368 * <ScrollRestoration />
1369 * <Scripts />
1370 * </body>
1371 * </html>
1372 * );
1373 * }
1374 * ```
1375 *
1376 * This component renders an inline `<script>` to prevent scroll flashing. The
1377 * `nonce` prop will be passed down to the script tag to allow CSP nonce usage.
1378 * If not provided in Framework Mode, it will default to any
1379 * {@link ServerRouter | `<ServerRouter nonce>`} prop.
1380 *
1381 * ```tsx
1382 * <ScrollRestoration nonce={cspNonce} />
1383 * ```
1384 *
1385 * @public
1386 * @category Components
1387 * @mode framework
1388 * @mode data
1389 * @param props Props
1390 * @param {ScrollRestorationProps.getKey} props.getKey n/a
1391 * @param {ScriptsProps.nonce} props.nonce n/a
1392 * @param {ScrollRestorationProps.storageKey} props.storageKey n/a
1393 * @returns A [`<script>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)
1394 * tag that restores scroll positions on navigation.
1395 */
1396declare function ScrollRestoration({
1397 getKey,
1398 storageKey,
1399 ...props
1400}: ScrollRestorationProps): React$1.JSX.Element | null;
1401declare namespace ScrollRestoration {
1402 var displayName: string;
1403}
1404/**
1405 * Handles the click behavior for router {@link Link | `<Link>`} components.This
1406 * is useful if you need to create custom {@link Link | `<Link>`} components with
1407 * the same click behavior we use in our exported {@link Link | `<Link>`}.
1408 *
1409 * @public
1410 * @category Hooks
1411 * @param to The URL to navigate to, can be a string or a partial {@link Path}.
1412 * @param options Options
1413 * @param options.preventScrollReset Whether to prevent the scroll position from
1414 * being reset to the top of the viewport on completion of the navigation when
1415 * using the {@link ScrollRestoration} component. Defaults to `false`.
1416 * @param options.relative The {@link RelativeRoutingType | relative routing type}
1417 * to use for the link. Defaults to `"route"`.
1418 * @param options.replace Whether to replace the current [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1419 * entry instead of pushing a new one. Defaults to `false`.
1420 * @param options.state The state to add to the [`History`](https://developer.mozilla.org/en-US/docs/Web/API/History)
1421 * entry for this navigation. Defaults to `undefined`.
1422 * @param options.target The target attribute for the link. Defaults to `undefined`.
1423 * @param options.viewTransition **Deprecated.** Use React's
1424 * [`<ViewTransition>`](https://react.dev/reference/react/ViewTransition) component
1425 * instead. See the [migration guide](../../how-to/view-transitions).
1426 * @param options.defaultShouldRevalidate Specify the default revalidation
1427 * behavior for the navigation. When not specified, loaders revalidate
1428 * according to the router's standard revalidation behavior.
1429 * @param options.mask Masked location to display in the browser instead
1430 * of the router location. Defaults to `undefined`.
1431 * @param options.useTransitions Wraps the navigation in
1432 * [`React.startTransition`](https://react.dev/reference/react/startTransition)
1433 * for concurrent rendering. Defaults to `false`.
1434 * @returns A click handler function that can be used in a custom {@link Link} component.
1435 */
1436declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, {
1437 target,
1438 replace: replaceProp,
1439 mask,
1440 state,
1441 preventScrollReset,
1442 relative,
1443 viewTransition,
1444 defaultShouldRevalidate,
1445 useTransitions
1446}?: {
1447 target?: React$1.HTMLAttributeAnchorTarget;
1448 replace?: boolean;
1449 mask?: To;
1450 state?: any;
1451 preventScrollReset?: boolean;
1452 relative?: RelativeRoutingType;
1453 defaultShouldRevalidate?: boolean;
1454 useTransitions?: boolean;
1455} & Pick<NavigateOptions, "viewTransition">): (event: React$1.MouseEvent<E, MouseEvent>) => void;
1456/**
1457 * Returns a tuple of the current URL's [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
1458 * and a function to update them. Setting the search params causes a navigation.
1459 *
1460 * ```tsx
1461 * import { useSearchParams } from "react-router";
1462 *
1463 * export function SomeComponent() {
1464 * const [searchParams, setSearchParams] = useSearchParams();
1465 * // ...
1466 * }
1467 * ```
1468 *
1469 * ### `setSearchParams` function
1470 *
1471 * The second element of the tuple is a function that can be used to update the
1472 * search params. It accepts the same types as `defaultInit` and will cause a
1473 * navigation to the new URL.
1474 *
1475 * ```tsx
1476 * let [searchParams, setSearchParams] = useSearchParams();
1477 *
1478 * // a search param string
1479 * setSearchParams("?tab=1");
1480 *
1481 * // a shorthand object
1482 * setSearchParams({ tab: "1" });
1483 *
1484 * // object keys can be arrays for multiple values on the key
1485 * setSearchParams({ brand: ["nike", "reebok"] });
1486 *
1487 * // an array of tuples
1488 * setSearchParams([["tab", "1"]]);
1489 *
1490 * // a `URLSearchParams` object
1491 * setSearchParams(new URLSearchParams("?tab=1"));
1492 * ```
1493 *
1494 * It also supports a function callback like React's
1495 * [`setState`](https://react.dev/reference/react/useState#setstate):
1496 *
1497 * ```tsx
1498 * setSearchParams((searchParams) => {
1499 * searchParams.set("tab", "2");
1500 * return searchParams;
1501 * });
1502 * ```
1503 *
1504 * <docs-warning>The function callback version of `setSearchParams` does not support
1505 * the [queueing](https://react.dev/reference/react/useState#setstate-parameters)
1506 * logic that React's `setState` implements. Multiple calls to `setSearchParams`
1507 * in the same tick will not build on the prior value. If you need this behavior,
1508 * you can use `setState` manually.</docs-warning>
1509 *
1510 * ### Notes
1511 *
1512 * Note that `searchParams` is a stable reference, so you can reliably use it
1513 * as a dependency in React's [`useEffect`](https://react.dev/reference/react/useEffect)
1514 * hooks.
1515 *
1516 * ```tsx
1517 * useEffect(() => {
1518 * console.log(searchParams.get("tab"));
1519 * }, [searchParams]);
1520 * ```
1521 *
1522 * However, this also means it's mutable. If you change the object without
1523 * calling `setSearchParams`, its values will change between renders if some
1524 * other state causes the component to re-render and URL will not reflect the
1525 * values.
1526 *
1527 * @public
1528 * @category Hooks
1529 * @param defaultInit
1530 * You can initialize the search params with a default value, though it **will
1531 * not** change the URL on the first render.
1532 *
1533 * ```tsx
1534 * // a search param string
1535 * useSearchParams("?tab=1");
1536 *
1537 * // a shorthand object
1538 * useSearchParams({ tab: "1" });
1539 *
1540 * // object keys can be arrays for multiple values on the key
1541 * useSearchParams({ brand: ["nike", "reebok"] });
1542 *
1543 * // an array of tuples
1544 * useSearchParams([["tab", "1"]]);
1545 *
1546 * // a `URLSearchParams` object
1547 * useSearchParams(new URLSearchParams("?tab=1"));
1548 * ```
1549 * @returns A tuple of the current [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
1550 * and a function to update them.
1551 */
1552declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
1553/**
1554 * Sets new search params and causes a navigation when called.
1555 *
1556 * ```tsx
1557 * <button
1558 * onClick={() => {
1559 * const params = new URLSearchParams();
1560 * params.set("someKey", "someValue");
1561 * setSearchParams(params, {
1562 * preventScrollReset: true,
1563 * });
1564 * }}
1565 * />
1566 * ```
1567 *
1568 * It also supports a function for setting new search params.
1569 *
1570 * ```tsx
1571 * <button
1572 * onClick={() => {
1573 * setSearchParams((prev) => {
1574 * prev.set("someKey", "someValue");
1575 * return prev;
1576 * });
1577 * }}
1578 * />
1579 * ```
1580 */
1581type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
1582/**
1583 * Submits a HTML [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)
1584 * to the server without reloading the page.
1585 */
1586interface SubmitFunction {
1587 (
1588 /**
1589 * Can be multiple types of elements and objects
1590 *
1591 * **[`HTMLFormElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement)**
1592 *
1593 * ```tsx
1594 * <Form
1595 * onSubmit={(event) => {
1596 * submit(event.currentTarget);
1597 * }}
1598 * />
1599 * ```
1600 *
1601 * **[`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
1602 *
1603 * ```tsx
1604 * const formData = new FormData();
1605 * formData.append("myKey", "myValue");
1606 * submit(formData, { method: "post" });
1607 * ```
1608 *
1609 * **Plain object that will be serialized as [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
1610 *
1611 * ```tsx
1612 * submit({ myKey: "myValue" }, { method: "post" });
1613 * ```
1614 *
1615 * **Plain object that will be serialized as JSON**
1616 *
1617 * ```tsx
1618 * submit(
1619 * { myKey: "myValue" },
1620 * { method: "post", encType: "application/json" }
1621 * );
1622 * ```
1623 */
1624 target: SubmitTarget,
1625 /**
1626 * Options that override the [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)'s
1627 * own attributes. Required when submitting arbitrary data without a backing
1628 * [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form).
1629 */
1630 options?: SubmitOptions): Promise<void>;
1631}
1632/**
1633 * Submits a fetcher [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) to the server without reloading the page.
1634 */
1635interface FetcherSubmitFunction {
1636 (
1637 /**
1638 * Can be multiple types of elements and objects
1639 *
1640 * **[`HTMLFormElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement)**
1641 *
1642 * ```tsx
1643 * <fetcher.Form
1644 * onSubmit={(event) => {
1645 * fetcher.submit(event.currentTarget);
1646 * }}
1647 * />
1648 * ```
1649 *
1650 * **[`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
1651 *
1652 * ```tsx
1653 * const formData = new FormData();
1654 * formData.append("myKey", "myValue");
1655 * fetcher.submit(formData, { method: "post" });
1656 * ```
1657 *
1658 * **Plain object that will be serialized as [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)**
1659 *
1660 * ```tsx
1661 * fetcher.submit({ myKey: "myValue" }, { method: "post" });
1662 * ```
1663 *
1664 * **Plain object that will be serialized as JSON**
1665 *
1666 * ```tsx
1667 * fetcher.submit(
1668 * { myKey: "myValue" },
1669 * { method: "post", encType: "application/json" }
1670 * );
1671 * ```
1672 */
1673 target: SubmitTarget, options?: FetcherSubmitOptions): Promise<void>;
1674}
1675/**
1676 * The imperative version of {@link Form | `<Form>`} that lets you submit a form
1677 * from code instead of a user interaction.
1678 *
1679 * The `viewTransition` submission option is deprecated. Use React's
1680 * [`<ViewTransition>`](https://react.dev/reference/react/ViewTransition) component
1681 * instead. See the [migration guide](../../how-to/view-transitions).
1682 *
1683 * @example
1684 * import { useSubmit } from "react-router";
1685 *
1686 * function SomeComponent() {
1687 * const submit = useSubmit();
1688 * return (
1689 * <Form onChange={(event) => submit(event.currentTarget)} />
1690 * );
1691 * }
1692 *
1693 * @public
1694 * @category Hooks
1695 * @mode framework
1696 * @mode data
1697 * @returns A function that can be called to submit a {@link Form} imperatively.
1698 */
1699declare function useSubmit(): SubmitFunction;
1700/**
1701 * Resolves the URL to the closest route in the component hierarchy instead of
1702 * the current URL of the app.
1703 *
1704 * This is used internally by {@link Form} to resolve the `action` to the closest
1705 * route, but can be used generically as well.
1706 *
1707 * ```ts
1708 * import { useFormAction } from "react-router";
1709 *
1710 * function SomeComponent() {
1711 * // closest route URL
1712 * let action = useFormAction();
1713 *
1714 * // closest route URL + "destroy"
1715 * let destroyAction = useFormAction("destroy");
1716 * }
1717 * ```
1718 *
1719 * <docs-info>This hook adds a `basename` if your app specifies one, so that it
1720 * can be used with raw `<form>` elements in a progressively enhanced way. If
1721 * you are using this to provide an `action` to `<Form>` or `fetcher.submit`, you
1722 * will need to remove the `basename` since both of those will prepend it
1723 * internally.</docs-info>
1724 *
1725 *
1726 * @public
1727 * @category Hooks
1728 * @mode framework
1729 * @mode data
1730 * @param action The action to append to the closest route URL. Defaults to the
1731 * closest route URL.
1732 * @param options Options
1733 * @param options.relative The relative routing type to use when resolving the
1734 * action. Defaults to `"route"`.
1735 * @returns The resolved action URL.
1736 */
1737declare function useFormAction(action?: string, {
1738 relative
1739}?: {
1740 relative?: RelativeRoutingType;
1741}): string;
1742/**
1743 * The return value {@link useFetcher} that keeps track of the state of a fetcher.
1744 *
1745 * ```tsx
1746 * let fetcher = useFetcher();
1747 * ```
1748 */
1749type FetcherWithComponents<TData> = Fetcher<TData> & {
1750 /**
1751 * Just like {@link Form} except it doesn't cause a navigation.
1752 *
1753 * ```tsx
1754 * function SomeComponent() {
1755 * const fetcher = useFetcher()
1756 * return (
1757 * <fetcher.Form method="post" action="/some/route">
1758 * <input type="text" />
1759 * </fetcher.Form>
1760 * )
1761 * }
1762 * ```
1763 */
1764 Form: React$1.ForwardRefExoticComponent<FetcherFormProps & React$1.RefAttributes<HTMLFormElement>>;
1765 /**
1766 * Loads data from a route. Useful for loading data imperatively inside user
1767 * events outside a normal button or form, like a combobox or search input.
1768 *
1769 * ```tsx
1770 * let fetcher = useFetcher()
1771 *
1772 * <input onChange={e => {
1773 * fetcher.load(`/search?q=${e.target.value}`)
1774 * }} />
1775 * ```
1776 */
1777 load: (href: string, opts?: {
1778 /**
1779 * Wraps the initial state update for this `fetcher.load` in a
1780 * [`ReactDOM.flushSync`](https://react.dev/reference/react-dom/flushSync)
1781 * call instead of the default [`React.startTransition`](https://react.dev/reference/react/startTransition).
1782 * This allows you to perform synchronous DOM actions immediately after the
1783 * update is flushed to the DOM.
1784 */
1785 flushSync?: boolean;
1786 }) => Promise<void>;
1787 /**
1788 * Reset a fetcher back to an empty/idle state.
1789 *
1790 * If the fetcher is currently in-flight, the
1791 * [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController)
1792 * will be aborted with the `reason`, if provided.
1793 * @param opts Options for resetting the fetcher.
1794 * @param opts.reason Optional `reason` to provide to [`AbortController.abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort)
1795 * @returns void
1796 */
1797 reset: (opts?: {
1798 reason?: unknown;
1799 }) => void;
1800 /**
1801 * Submits form data to a route. While multiple nested routes can match a URL, only the leaf route will be called.
1802 *
1803 * The `formData` can be multiple types:
1804 *
1805 * - [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
1806 * A `FormData` instance.
1807 * - [`HTMLFormElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement)
1808 * A [`<form>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) DOM element.
1809 * - `Object`
1810 * An object of key/value-pairs that will be converted to a [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
1811 * instance by default. You can pass a more complex object and serialize it
1812 * as JSON by specifying `encType: "application/json"`. See
1813 * {@link useSubmit} for more details.
1814 *
1815 * If the method is `GET`, then the route [`loader`](../../start/framework/route-module#loader)
1816 * is being called and with the `formData` serialized to the url as [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).
1817 * If `DELETE`, `PATCH`, `POST`, or `PUT`, then the route [`action`](../../start/framework/route-module#action)
1818 * is being called with `formData` as the body.
1819 *
1820 * ```tsx
1821 * // Submit a FormData instance (GET request)
1822 * const formData = new FormData();
1823 * fetcher.submit(formData);
1824 *
1825 * // Submit the HTML form element
1826 * fetcher.submit(event.currentTarget.form, {
1827 * method: "POST",
1828 * });
1829 *
1830 * // Submit key/value JSON as a FormData instance
1831 * fetcher.submit(
1832 * { serialized: "values" },
1833 * { method: "POST" }
1834 * );
1835 *
1836 * // Submit raw JSON
1837 * fetcher.submit(
1838 * {
1839 * deeply: {
1840 * nested: {
1841 * json: "values",
1842 * },
1843 * },
1844 * },
1845 * {
1846 * method: "POST",
1847 * encType: "application/json",
1848 * }
1849 * );
1850 * ```
1851 */
1852 submit: FetcherSubmitFunction;
1853};
1854/**
1855 * Useful for creating complex, dynamic user interfaces that require multiple,
1856 * concurrent data interactions without causing a navigation.
1857 *
1858 * Fetchers track their own, independent state and can be used to load data, submit
1859 * forms, and generally interact with [`action`](../../start/framework/route-module#action)
1860 * and [`loader`](../../start/framework/route-module#loader) functions.
1861 *
1862 * @example
1863 * import { useFetcher } from "react-router"
1864 *
1865 * function SomeComponent() {
1866 * let fetcher = useFetcher()
1867 *
1868 * // states are available on the fetcher
1869 * fetcher.state // "idle" | "loading" | "submitting"
1870 * fetcher.data // the data returned from the action or loader
1871 *
1872 * // render a form
1873 * <fetcher.Form method="post" />
1874 *
1875 * // load data
1876 * fetcher.load("/some/route")
1877 *
1878 * // submit data
1879 * fetcher.submit(someFormRef, { method: "post" })
1880 * fetcher.submit(someData, {
1881 * method: "post",
1882 * encType: "application/json"
1883 * })
1884 *
1885 * // reset fetcher
1886 * fetcher.reset()
1887 * }
1888 *
1889 * @public
1890 * @category Hooks
1891 * @mode framework
1892 * @mode data
1893 * @param options Options
1894 * @param options.key A unique key to identify the fetcher.
1895 *
1896 *
1897 * By default, `useFetcher` generates a unique fetcher scoped to that component.
1898 * If you want to identify a fetcher with your own key such that you can access
1899 * it from elsewhere in your app, you can do that with the `key` option:
1900 *
1901 * ```tsx
1902 * function SomeComp() {
1903 * let fetcher = useFetcher({ key: "my-key" })
1904 * // ...
1905 * }
1906 *
1907 * // Somewhere else
1908 * function AnotherComp() {
1909 * // this will be the same fetcher, sharing the state across the app
1910 * let fetcher = useFetcher({ key: "my-key" });
1911 * // ...
1912 * }
1913 * ```
1914 * @returns A {@link FetcherWithComponents} object that contains the fetcher's state, data, and components for submitting forms and loading data.
1915 */
1916declare function useFetcher<T = any>({
1917 key
1918}?: {
1919 key?: string;
1920}): FetcherWithComponents<SerializeFrom<T>>;
1921/**
1922 * Returns an array of all in-flight {@link Fetcher}s. This is useful for components
1923 * throughout the app that didn't create the fetchers but want to use their submissions
1924 * to participate in optimistic UI.
1925 *
1926 * @example
1927 * import { useFetchers } from "react-router";
1928 *
1929 * function SomeComponent() {
1930 * const fetchers = useFetchers();
1931 * fetchers[0].formData; // FormData
1932 * fetchers[0].state; // etc.
1933 * // ...
1934 * }
1935 *
1936 * @public
1937 * @category Hooks
1938 * @mode framework
1939 * @mode data
1940 * @returns An array of all in-flight {@link Fetcher}s, each with a unique `key`
1941 * property.
1942 */
1943declare function useFetchers(): (Fetcher & {
1944 key: string;
1945})[];
1946/**
1947 * When rendered inside a {@link RouterProvider}, will restore scroll positions
1948 * on navigations
1949 *
1950 * <!--
1951 * Not marked `@public` because we only export as UNSAFE_ and therefore we don't
1952 * maintain an .md file for this hook
1953 * -->
1954 *
1955 * @name UNSAFE_useScrollRestoration
1956 * @category Hooks
1957 * @mode framework
1958 * @mode data
1959 * @param options Options
1960 * @param options.getKey A function that returns a key to use for scroll restoration.
1961 * This is useful for custom scroll restoration logic, such as using only the pathname
1962 * so that subsequent navigations to prior paths will restore the scroll. Defaults
1963 * to `location.key`.
1964 * @param options.storageKey The key to use for storing scroll positions in
1965 * `sessionStorage`. Defaults to `"react-router-scroll-positions"`.
1966 * @returns {void}
1967 */
1968declare function useScrollRestoration({
1969 getKey,
1970 storageKey
1971}?: {
1972 getKey?: GetScrollRestorationKeyFunction;
1973 storageKey?: string;
1974}): void;
1975/**
1976 * Set up a callback to be fired on [Window's `beforeunload` event](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event).
1977 *
1978 * @public
1979 * @category Hooks
1980 * @param callback The callback to be called when the [`beforeunload` event](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event)
1981 * is fired.
1982 * @param options Options
1983 * @param options.capture If `true`, the event will be captured during the capture
1984 * phase. Defaults to `false`.
1985 * @returns {void}
1986 */
1987declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
1988 capture?: boolean;
1989}): void;
1990/**
1991 * Wrapper around {@link useBlocker} to show a [`window.confirm`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm)
1992 * prompt to users instead of building a custom UI with {@link useBlocker}.
1993 *
1994 * The `unstable_` flag will not be removed because this technique has a lot of
1995 * rough edges and behaves very differently (and incorrectly sometimes) across
1996 * browsers if users click addition back/forward navigations while the
1997 * confirmation is open. Use at your own risk.
1998 *
1999 * @example
2000 * function ImportantForm() {
2001 * let [value, setValue] = React.useState("");
2002 *
2003 * // Block navigating elsewhere when data has been entered into the input
2004 * unstable_usePrompt({
2005 * message: "Are you sure?",
2006 * when: ({ currentLocation, nextLocation }) =>
2007 * value !== "" &&
2008 * currentLocation.pathname !== nextLocation.pathname,
2009 * });
2010 *
2011 * return (
2012 * <Form method="post">
2013 * <label>
2014 * Enter some important data:
2015 * <input
2016 * name="data"
2017 * value={value}
2018 * onChange={(e) => setValue(e.target.value)}
2019 * />
2020 * </label>
2021 * <button type="submit">Save</button>
2022 * </Form>
2023 * );
2024 * }
2025 *
2026 * @name unstable_usePrompt
2027 * @public
2028 * @category Hooks
2029 * @mode framework
2030 * @mode data
2031 * @param options Options
2032 * @param options.message The message to show in the confirmation dialog.
2033 * @param options.when A boolean or a function that returns a boolean indicating
2034 * whether to block the navigation. If a function is provided, it will receive an
2035 * object with `currentLocation` and `nextLocation` properties.
2036 * @returns {void}
2037 */
2038declare function usePrompt({
2039 when,
2040 message
2041}: {
2042 when: boolean | BlockerFunction;
2043 message: string;
2044}): void;
2045/**
2046 * **Deprecated.** Use React's [`<ViewTransition>`](https://react.dev/reference/react/ViewTransition)
2047 * component to style transitions instead. This hook only tracks React Router's
2048 * legacy view transitions, not transitions started by React. See the
2049 * [migration guide](../../how-to/view-transitions).
2050 *
2051 * This hook returns `true` when there is an active [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
2052 * and the specified location matches either side of the navigation (the URL you are
2053 * navigating **to** or the URL you are navigating **from**). This can be used to apply finer-grained styles to
2054 * elements to further customize the view transition. This requires that view
2055 * transitions have been enabled for the given navigation via {@link LinkProps.viewTransition}
2056 * (or the `Form`, `submit`, or `navigate` call)
2057 *
2058 * @public
2059 * @category Hooks
2060 * @mode framework
2061 * @mode data
2062 * @param to The {@link To} location to compare against the active transition's current
2063 * and next URLs.
2064 * @param options Options
2065 * @param options.relative The relative routing type to use when resolving the
2066 * `to` location, defaults to `"route"`. See {@link RelativeRoutingType} for
2067 * more details.
2068 * @returns `true` if there is an active [View Transition](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API)
2069 * and the resolved path matches the transition's destination or source pathname, otherwise `false`.
2070 *
2071 * @deprecated Use React's `<ViewTransition>` component instead.
2072 */
2073declare function useViewTransitionState(to: To, {
2074 relative
2075}?: {
2076 relative?: RelativeRoutingType;
2077}): boolean;
2078//#endregion
2079export { BrowserRouter, BrowserRouterProps, DOMRouterOpts, FetcherFormProps, FetcherSubmitFunction, FetcherWithComponents, Form, FormProps, HashRouter, HashRouterProps, HistoryRouter, HistoryRouterProps, Link, LinkProps, NavLink, NavLinkProps, NavLinkRenderProps, ScrollRestoration, ScrollRestorationProps, SetURLSearchParams, SubmitFunction, createBrowserRouter, createHashRouter, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, usePrompt, useScrollRestoration, useSearchParams, useSubmit, useViewTransitionState };
\No newline at end of file