react-router-dom 5.2.0 → 6.11.2

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 (70) hide show
  1. package/CHANGELOG.md +345 -0
  2. package/{LICENSE → LICENSE.md} +3 -1
  3. package/README.md +4 -36
  4. package/dist/dom.d.ts +76 -0
  5. package/dist/index.d.ts +246 -0
  6. package/dist/index.js +1058 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/main.js +19 -0
  9. package/dist/react-router-dom.development.js +1005 -0
  10. package/dist/react-router-dom.development.js.map +1 -0
  11. package/dist/react-router-dom.production.min.js +12 -0
  12. package/dist/react-router-dom.production.min.js.map +1 -0
  13. package/dist/server.d.ts +28 -0
  14. package/dist/server.js +319 -0
  15. package/dist/server.mjs +291 -0
  16. package/dist/umd/react-router-dom.development.js +1306 -0
  17. package/dist/umd/react-router-dom.development.js.map +1 -0
  18. package/dist/umd/react-router-dom.production.min.js +12 -0
  19. package/dist/umd/react-router-dom.production.min.js.map +1 -0
  20. package/package.json +38 -54
  21. package/server.d.ts +28 -0
  22. package/server.js +319 -0
  23. package/server.mjs +291 -0
  24. package/BrowserRouter.js +0 -3
  25. package/HashRouter.js +0 -3
  26. package/Link.js +0 -3
  27. package/MemoryRouter.js +0 -3
  28. package/NavLink.js +0 -3
  29. package/Prompt.js +0 -3
  30. package/Redirect.js +0 -3
  31. package/Route.js +0 -3
  32. package/Router.js +0 -3
  33. package/StaticRouter.js +0 -3
  34. package/Switch.js +0 -3
  35. package/cjs/react-router-dom.js +0 -443
  36. package/cjs/react-router-dom.js.map +0 -1
  37. package/cjs/react-router-dom.min.js +0 -2
  38. package/cjs/react-router-dom.min.js.map +0 -1
  39. package/es/BrowserRouter.js +0 -5
  40. package/es/HashRouter.js +0 -5
  41. package/es/Link.js +0 -5
  42. package/es/MemoryRouter.js +0 -5
  43. package/es/NavLink.js +0 -5
  44. package/es/Prompt.js +0 -5
  45. package/es/Redirect.js +0 -5
  46. package/es/Route.js +0 -5
  47. package/es/Router.js +0 -5
  48. package/es/StaticRouter.js +0 -5
  49. package/es/Switch.js +0 -5
  50. package/es/generatePath.js +0 -5
  51. package/es/matchPath.js +0 -5
  52. package/es/warnAboutDeprecatedESMImport.js +0 -34
  53. package/es/withRouter.js +0 -5
  54. package/esm/react-router-dom.js +0 -317
  55. package/esm/react-router-dom.js.map +0 -1
  56. package/generatePath.js +0 -3
  57. package/index.js +0 -7
  58. package/matchPath.js +0 -3
  59. package/modules/BrowserRouter.js +0 -36
  60. package/modules/HashRouter.js +0 -35
  61. package/modules/Link.js +0 -146
  62. package/modules/NavLink.js +0 -125
  63. package/modules/index.js +0 -21
  64. package/modules/utils/locationUtils.js +0 -10
  65. package/umd/react-router-dom.js +0 -3969
  66. package/umd/react-router-dom.js.map +0 -1
  67. package/umd/react-router-dom.min.js +0 -2
  68. package/umd/react-router-dom.min.js.map +0 -1
  69. package/warnAboutDeprecatedCJSRequire.js +0 -36
  70. package/withRouter.js +0 -3
@@ -0,0 +1,246 @@
1
+ /**
2
+ * NOTE: If you refactor this to split up the modules into separate files,
3
+ * you'll need to update the rollup config for react-router-dom-v5-compat.
4
+ */
5
+ import * as React from "react";
6
+ import type { NavigateOptions, RelativeRoutingType, RouteObject, To } from "react-router";
7
+ import type { Fetcher, FormEncType, FormMethod, FutureConfig, GetScrollRestorationKeyFunction, History, HTMLFormMethod, HydrationState, Router as RemixRouter, V7_FormMethod } from "@remix-run/router";
8
+ import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit } from "./dom";
9
+ import { createSearchParams } from "./dom";
10
+ export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, V7_FormMethod, };
11
+ export { createSearchParams };
12
+ export type { ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, } from "react-router";
13
+ export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router";
14
+ /** @internal */
15
+ export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, } from "react-router";
16
+ declare global {
17
+ var __staticRouterHydrationData: HydrationState | undefined;
18
+ }
19
+ interface DOMRouterOpts {
20
+ basename?: string;
21
+ future?: Partial<Omit<FutureConfig, "v7_prependBasename">>;
22
+ hydrationData?: HydrationState;
23
+ window?: Window;
24
+ }
25
+ export declare function createBrowserRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter;
26
+ export declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter;
27
+ export interface BrowserRouterProps {
28
+ basename?: string;
29
+ children?: React.ReactNode;
30
+ window?: Window;
31
+ }
32
+ /**
33
+ * A `<Router>` for use in web browsers. Provides the cleanest URLs.
34
+ */
35
+ export declare function BrowserRouter({ basename, children, window, }: BrowserRouterProps): JSX.Element;
36
+ export interface HashRouterProps {
37
+ basename?: string;
38
+ children?: React.ReactNode;
39
+ window?: Window;
40
+ }
41
+ /**
42
+ * A `<Router>` for use in web browsers. Stores the location in the hash
43
+ * portion of the URL so it is not sent to the server.
44
+ */
45
+ export declare function HashRouter({ basename, children, window }: HashRouterProps): JSX.Element;
46
+ export interface HistoryRouterProps {
47
+ basename?: string;
48
+ children?: React.ReactNode;
49
+ history: History;
50
+ }
51
+ /**
52
+ * A `<Router>` that accepts a pre-instantiated history object. It's important
53
+ * to note that using your own history object is highly discouraged and may add
54
+ * two versions of the history library to your bundles unless you use the same
55
+ * version of the history library that React Router uses internally.
56
+ */
57
+ declare function HistoryRouter({ basename, children, history }: HistoryRouterProps): JSX.Element;
58
+ declare namespace HistoryRouter {
59
+ var displayName: string;
60
+ }
61
+ export { HistoryRouter as unstable_HistoryRouter };
62
+ export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
63
+ reloadDocument?: boolean;
64
+ replace?: boolean;
65
+ state?: any;
66
+ preventScrollReset?: boolean;
67
+ relative?: RelativeRoutingType;
68
+ to: To;
69
+ }
70
+ /**
71
+ * The public API for rendering a history-aware <a>.
72
+ */
73
+ export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
74
+ export interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
75
+ children?: React.ReactNode | ((props: {
76
+ isActive: boolean;
77
+ isPending: boolean;
78
+ }) => React.ReactNode);
79
+ caseSensitive?: boolean;
80
+ className?: string | ((props: {
81
+ isActive: boolean;
82
+ isPending: boolean;
83
+ }) => string | undefined);
84
+ end?: boolean;
85
+ style?: React.CSSProperties | ((props: {
86
+ isActive: boolean;
87
+ isPending: boolean;
88
+ }) => React.CSSProperties | undefined);
89
+ }
90
+ /**
91
+ * A <Link> wrapper that knows if it's "active" or not.
92
+ */
93
+ export declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
94
+ export interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {
95
+ /**
96
+ * The HTTP verb to use when the form is submit. Supports "get", "post",
97
+ * "put", "delete", "patch".
98
+ */
99
+ method?: HTMLFormMethod;
100
+ /**
101
+ * Normal `<form action>` but supports React Router's relative paths.
102
+ */
103
+ action?: string;
104
+ /**
105
+ * Forces a full document navigation instead of a fetch.
106
+ */
107
+ reloadDocument?: boolean;
108
+ /**
109
+ * Replaces the current entry in the browser history stack when the form
110
+ * navigates. Use this if you don't want the user to be able to click "back"
111
+ * to the page with the form on it.
112
+ */
113
+ replace?: boolean;
114
+ /**
115
+ * Determines whether the form action is relative to the route hierarchy or
116
+ * the pathname. Use this if you want to opt out of navigating the route
117
+ * hierarchy and want to instead route based on /-delimited URL segments
118
+ */
119
+ relative?: RelativeRoutingType;
120
+ /**
121
+ * Prevent the scroll position from resetting to the top of the viewport on
122
+ * completion of the navigation when using the <ScrollRestoration> component
123
+ */
124
+ preventScrollReset?: boolean;
125
+ /**
126
+ * A function to call when the form is submitted. If you call
127
+ * `event.preventDefault()` then this form will not do anything.
128
+ */
129
+ onSubmit?: React.FormEventHandler<HTMLFormElement>;
130
+ }
131
+ /**
132
+ * A `@remix-run/router`-aware `<form>`. It behaves like a normal form except
133
+ * that the interaction with the server is with `fetch` instead of new document
134
+ * requests, allowing components to add nicer UX to the page as the form is
135
+ * submitted and returns with data.
136
+ */
137
+ export declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
138
+ export interface ScrollRestorationProps {
139
+ getKey?: GetScrollRestorationKeyFunction;
140
+ storageKey?: string;
141
+ }
142
+ /**
143
+ * This component will emulate the browser's scroll restoration on location
144
+ * changes.
145
+ */
146
+ export declare function ScrollRestoration({ getKey, storageKey, }: ScrollRestorationProps): null;
147
+ export declare namespace ScrollRestoration {
148
+ var displayName: string;
149
+ }
150
+ /**
151
+ * Handles the click behavior for router `<Link>` components. This is useful if
152
+ * you need to create custom `<Link>` components with the same click behavior we
153
+ * use in our exported `<Link>`.
154
+ */
155
+ export declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, preventScrollReset, relative, }?: {
156
+ target?: React.HTMLAttributeAnchorTarget;
157
+ replace?: boolean;
158
+ state?: any;
159
+ preventScrollReset?: boolean;
160
+ relative?: RelativeRoutingType;
161
+ }): (event: React.MouseEvent<E, MouseEvent>) => void;
162
+ /**
163
+ * A convenient wrapper for reading and writing search parameters via the
164
+ * URLSearchParams interface.
165
+ */
166
+ export declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
167
+ export declare type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
168
+ declare type SubmitTarget = HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | {
169
+ [name: string]: string;
170
+ } | null;
171
+ /**
172
+ * Submits a HTML `<form>` to the server without reloading the page.
173
+ */
174
+ export interface SubmitFunction {
175
+ (
176
+ /**
177
+ * Specifies the `<form>` to be submitted to the server, a specific
178
+ * `<button>` or `<input type="submit">` to use to submit the form, or some
179
+ * arbitrary data to submit.
180
+ *
181
+ * Note: When using a `<button>` its `name` and `value` will also be
182
+ * included in the form data that is submitted.
183
+ */
184
+ target: SubmitTarget,
185
+ /**
186
+ * Options that override the `<form>`'s own attributes. Required when
187
+ * submitting arbitrary data without a backing `<form>`.
188
+ */
189
+ options?: SubmitOptions): void;
190
+ }
191
+ /**
192
+ * Returns a function that may be used to programmatically submit a form (or
193
+ * some arbitrary data) to the server.
194
+ */
195
+ export declare function useSubmit(): SubmitFunction;
196
+ export declare function useFormAction(action?: string, { relative }?: {
197
+ relative?: RelativeRoutingType;
198
+ }): string;
199
+ declare function createFetcherForm(fetcherKey: string, routeId: string): React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
200
+ export declare type FetcherWithComponents<TData> = Fetcher<TData> & {
201
+ Form: ReturnType<typeof createFetcherForm>;
202
+ submit: (target: SubmitTarget, options?: Omit<SubmitOptions, "replace" | "preventScrollReset">) => void;
203
+ load: (href: string) => void;
204
+ };
205
+ /**
206
+ * Interacts with route loaders and actions without causing a navigation. Great
207
+ * for any interaction that stays on the same page.
208
+ */
209
+ export declare function useFetcher<TData = any>(): FetcherWithComponents<TData>;
210
+ /**
211
+ * Provides all fetchers currently on the page. Useful for layouts and parent
212
+ * routes that need to provide pending/optimistic UI regarding the fetch.
213
+ */
214
+ export declare function useFetchers(): Fetcher[];
215
+ /**
216
+ * When rendered inside a RouterProvider, will restore scroll positions on navigations
217
+ */
218
+ declare function useScrollRestoration({ getKey, storageKey, }?: {
219
+ getKey?: GetScrollRestorationKeyFunction;
220
+ storageKey?: string;
221
+ }): void;
222
+ export { useScrollRestoration as UNSAFE_useScrollRestoration };
223
+ /**
224
+ * Setup a callback to be fired on the window's `beforeunload` event. This is
225
+ * useful for saving some data to `window.localStorage` just before the page
226
+ * refreshes.
227
+ *
228
+ * Note: The `callback` argument should be a function created with
229
+ * `React.useCallback()`.
230
+ */
231
+ export declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: {
232
+ capture?: boolean;
233
+ }): void;
234
+ /**
235
+ * Wrapper around useBlocker to show a window.confirm prompt to users instead
236
+ * of building a custom UI with useBlocker.
237
+ *
238
+ * Warning: This has *a lot of rough edges* and behaves very differently (and
239
+ * very incorrectly in some cases) across browsers if user click addition
240
+ * back/forward navigations while the confirm is open. Use at your own risk.
241
+ */
242
+ declare function usePrompt({ when, message }: {
243
+ when: boolean;
244
+ message: string;
245
+ }): void;
246
+ export { usePrompt as unstable_usePrompt };