react-router-dom-v5-compat 6.10.0 → 6.11.0-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE.md +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +71 -41
- package/dist/index.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router-dom/dom.d.ts +3 -7
- package/dist/react-router-dom/index.d.ts +2 -2
- package/dist/umd/react-router-dom-v5-compat.development.js +72 -38
- package/dist/umd/react-router-dom-v5-compat.development.js.map +1 -1
- package/dist/umd/react-router-dom-v5-compat.production.min.js +2 -2
- package/dist/umd/react-router-dom-v5-compat.production.min.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# `react-router-dom-v5-compat`
|
|
2
2
|
|
|
3
|
+
## 6.11.0-pre.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- `react-router-dom@6.11.0-pre.1`
|
|
9
|
+
- `react-router@6.11.0-pre.1`
|
|
10
|
+
|
|
11
|
+
## 6.11.0-pre.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies:
|
|
16
|
+
- `react-router@6.11.0-pre.0`
|
|
17
|
+
- `react-router-dom@6.11.0-pre.0`
|
|
18
|
+
|
|
3
19
|
## 6.10.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/LICENSE.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) React Training 2015-2019
|
|
4
|
-
Copyright (c) Remix Software 2020-
|
|
3
|
+
Copyright (c) React Training LLC 2015-2019
|
|
4
|
+
Copyright (c) Remix Software Inc. 2020-2021
|
|
5
|
+
Copyright (c) Shopify Inc. 2022-2023
|
|
5
6
|
|
|
6
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
* deprecate the deep require if we wanted to avoid the duplication here.
|
|
48
48
|
*/
|
|
49
49
|
export type { BrowserRouterProps, Hash, HashRouterProps, HistoryRouterProps, LinkProps, Location, Path, To, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigator, NavLinkProps, OutletProps, Params, ParamParseKey, PathMatch, RouteMatch, RouteObject, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, Pathname, Search, RoutesProps, ParamKeyValuePair, URLSearchParamsInit, ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, FetcherWithComponents, FormEncType, FormMethod, FormProps, GetScrollRestorationKeyFunction, IndexRouteObject, JsonFunction, LoaderFunction, LoaderFunctionArgs, Navigation, NonIndexRouteObject, PathPattern, RedirectFunction, RelativeRoutingType, RouterProviderProps, ScrollRestorationProps, ShouldRevalidateFunction, SubmitFunction, SubmitOptions, } from "./react-router-dom";
|
|
50
|
-
export { BrowserRouter, HashRouter, Link, MemoryRouter, NavLink, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, createSearchParams, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, unstable_HistoryRouter, useHref, useInRouterContext, useLinkClickHandler, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams, AbortedDeferredError, Await, RouterProvider, ScrollRestoration, createBrowserRouter, createHashRouter, createMemoryRouter, createRoutesFromElements, defer, isRouteErrorResponse, Form, json, redirect, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, unstable_useBlocker, useFetcher, useFetchers, useFormAction, useLoaderData, useMatches, useNavigation, unstable_usePrompt, useRevalidator, useRouteError, useRouteLoaderData, useSubmit, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_useScrollRestoration, } from "./react-router-dom";
|
|
50
|
+
export { BrowserRouter, HashRouter, Link, MemoryRouter, NavLink, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, createSearchParams, generatePath, matchPath, matchRoutes, parsePath, renderMatches, resolvePath, unstable_HistoryRouter, useHref, useInRouterContext, useLinkClickHandler, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams, AbortedDeferredError, Await, RouterProvider, ScrollRestoration, createBrowserRouter, createHashRouter, createMemoryRouter, createRoutesFromElements, defer, isRouteErrorResponse, Form, json, redirect, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, unstable_useBlocker, useFetcher, useFetchers, useFormAction, useLoaderData, useMatches, useNavigation, unstable_usePrompt, useRevalidator, useRouteError, useRouteLoaderData, useSubmit, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_useScrollRestoration, UNSAFE_useRouteId, } from "./react-router-dom";
|
|
51
51
|
export type { StaticRouterProps } from "./lib/components";
|
|
52
52
|
export { CompatRouter, CompatRoute, StaticRouter } from "./lib/components";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router DOM v5 Compat v6.
|
|
2
|
+
* React Router DOM v5 Compat v6.11.0-pre.1
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import * as React from 'react';
|
|
12
|
-
import {
|
|
13
|
-
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router';
|
|
14
|
-
import { createRouter, createBrowserHistory, createHashHistory, ErrorResponse,
|
|
12
|
+
import { UNSAFE_mapRouteProperties, Router, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, useNavigate, createPath, UNSAFE_useRouteId, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_DataRouterContext, Routes, Route } from 'react-router';
|
|
13
|
+
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router';
|
|
14
|
+
import { stripBasename, createRouter, createBrowserHistory, createHashHistory, ErrorResponse, UNSAFE_warning, UNSAFE_invariant, joinPaths } from '@remix-run/router';
|
|
15
15
|
import { parsePath, Action, createPath as createPath$1 } from 'history';
|
|
16
16
|
import { Route as Route$1, useHistory } from 'react-router-dom';
|
|
17
17
|
|
|
@@ -119,16 +119,26 @@ function getSearchParamsForLocation(locationSearch, defaultSearchParams) {
|
|
|
119
119
|
|
|
120
120
|
return searchParams;
|
|
121
121
|
}
|
|
122
|
-
function getFormSubmissionInfo(target,
|
|
122
|
+
function getFormSubmissionInfo(target, options, basename) {
|
|
123
123
|
let method;
|
|
124
|
-
let action;
|
|
124
|
+
let action = null;
|
|
125
125
|
let encType;
|
|
126
126
|
let formData;
|
|
127
127
|
|
|
128
128
|
if (isFormElement(target)) {
|
|
129
129
|
let submissionTrigger = options.submissionTrigger;
|
|
130
|
+
|
|
131
|
+
if (options.action) {
|
|
132
|
+
action = options.action;
|
|
133
|
+
} else {
|
|
134
|
+
// When grabbing the action from the element, it will have had the basename
|
|
135
|
+
// prefixed to ensure non-JS scenarios work, so strip it since we'll
|
|
136
|
+
// re-prefix in the router
|
|
137
|
+
let attr = target.getAttribute("action");
|
|
138
|
+
action = attr ? stripBasename(attr, basename) : null;
|
|
139
|
+
}
|
|
140
|
+
|
|
130
141
|
method = options.method || target.getAttribute("method") || defaultMethod;
|
|
131
|
-
action = options.action || target.getAttribute("action") || defaultAction;
|
|
132
142
|
encType = options.encType || target.getAttribute("enctype") || defaultEncType;
|
|
133
143
|
formData = new FormData(target);
|
|
134
144
|
|
|
@@ -143,8 +153,17 @@ function getFormSubmissionInfo(target, defaultAction, options) {
|
|
|
143
153
|
} // <button>/<input type="submit"> may override attributes of <form>
|
|
144
154
|
|
|
145
155
|
|
|
156
|
+
if (options.action) {
|
|
157
|
+
action = options.action;
|
|
158
|
+
} else {
|
|
159
|
+
// When grabbing the action from the element, it will have had the basename
|
|
160
|
+
// prefixed to ensure non-JS scenarios work, so strip it since we'll
|
|
161
|
+
// re-prefix in the router
|
|
162
|
+
let attr = target.getAttribute("formaction") || form.getAttribute("action");
|
|
163
|
+
action = attr ? stripBasename(attr, basename) : null;
|
|
164
|
+
}
|
|
165
|
+
|
|
146
166
|
method = options.method || target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
|
|
147
|
-
action = options.action || target.getAttribute("formaction") || form.getAttribute("action") || defaultAction;
|
|
148
167
|
encType = options.encType || target.getAttribute("formenctype") || form.getAttribute("enctype") || defaultEncType;
|
|
149
168
|
formData = new FormData(form); // Include name + value from a <button>, appending in case the button name
|
|
150
169
|
// matches an existing input name
|
|
@@ -156,7 +175,7 @@ function getFormSubmissionInfo(target, defaultAction, options) {
|
|
|
156
175
|
throw new Error("Cannot submit element that is not <form>, <button>, or " + "<input type=\"submit|image\">");
|
|
157
176
|
} else {
|
|
158
177
|
method = options.method || defaultMethod;
|
|
159
|
-
action = options.action ||
|
|
178
|
+
action = options.action || null;
|
|
160
179
|
encType = options.encType || defaultEncType;
|
|
161
180
|
|
|
162
181
|
if (target instanceof FormData) {
|
|
@@ -176,13 +195,8 @@ function getFormSubmissionInfo(target, defaultAction, options) {
|
|
|
176
195
|
}
|
|
177
196
|
}
|
|
178
197
|
|
|
179
|
-
let {
|
|
180
|
-
protocol,
|
|
181
|
-
host
|
|
182
|
-
} = window.location;
|
|
183
|
-
let url = new URL(action, protocol + "//" + host);
|
|
184
198
|
return {
|
|
185
|
-
|
|
199
|
+
action,
|
|
186
200
|
method: method.toLowerCase(),
|
|
187
201
|
encType,
|
|
188
202
|
formData
|
|
@@ -195,25 +209,29 @@ const _excluded = ["onClick", "relative", "reloadDocument", "replace", "state",
|
|
|
195
209
|
function createBrowserRouter(routes, opts) {
|
|
196
210
|
return createRouter({
|
|
197
211
|
basename: opts == null ? void 0 : opts.basename,
|
|
198
|
-
future: opts == null ? void 0 : opts.future,
|
|
212
|
+
future: _extends({}, opts == null ? void 0 : opts.future, {
|
|
213
|
+
v7_prependBasename: true
|
|
214
|
+
}),
|
|
199
215
|
history: createBrowserHistory({
|
|
200
216
|
window: opts == null ? void 0 : opts.window
|
|
201
217
|
}),
|
|
202
218
|
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
|
203
219
|
routes,
|
|
204
|
-
|
|
220
|
+
mapRouteProperties: UNSAFE_mapRouteProperties
|
|
205
221
|
}).initialize();
|
|
206
222
|
}
|
|
207
223
|
function createHashRouter(routes, opts) {
|
|
208
224
|
return createRouter({
|
|
209
225
|
basename: opts == null ? void 0 : opts.basename,
|
|
210
|
-
future: opts == null ? void 0 : opts.future,
|
|
226
|
+
future: _extends({}, opts == null ? void 0 : opts.future, {
|
|
227
|
+
v7_prependBasename: true
|
|
228
|
+
}),
|
|
211
229
|
history: createHashHistory({
|
|
212
230
|
window: opts == null ? void 0 : opts.window
|
|
213
231
|
}),
|
|
214
232
|
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
|
215
233
|
routes,
|
|
216
|
-
|
|
234
|
+
mapRouteProperties: UNSAFE_mapRouteProperties
|
|
217
235
|
}).initialize();
|
|
218
236
|
}
|
|
219
237
|
|
|
@@ -383,15 +401,20 @@ const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref4, ref) {
|
|
|
383
401
|
absoluteHref = to; // Only check for external origins client-side
|
|
384
402
|
|
|
385
403
|
if (isBrowser) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
404
|
+
try {
|
|
405
|
+
let currentUrl = new URL(window.location.href);
|
|
406
|
+
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
|
|
407
|
+
let path = stripBasename(targetUrl.pathname, basename);
|
|
408
|
+
|
|
409
|
+
if (targetUrl.origin === currentUrl.origin && path != null) {
|
|
410
|
+
// Strip the protocol/origin/basename for same-origin absolute URLs
|
|
411
|
+
to = path + targetUrl.search + targetUrl.hash;
|
|
412
|
+
} else {
|
|
413
|
+
isExternal = true;
|
|
414
|
+
}
|
|
415
|
+
} catch (e) {
|
|
416
|
+
// We can't do external URL detection without a valid URL
|
|
417
|
+
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "<Link to=\"" + to + "\"> contains an invalid URL which will probably break " + "when clicked - please update to a valid URL path.") : void 0;
|
|
395
418
|
}
|
|
396
419
|
}
|
|
397
420
|
} // Rendered into <a href> for relative URLs
|
|
@@ -689,11 +712,14 @@ function useSubmit() {
|
|
|
689
712
|
return useSubmitImpl();
|
|
690
713
|
}
|
|
691
714
|
|
|
692
|
-
function useSubmitImpl(fetcherKey,
|
|
715
|
+
function useSubmitImpl(fetcherKey, fetcherRouteId) {
|
|
693
716
|
let {
|
|
694
717
|
router
|
|
695
718
|
} = useDataRouterContext(DataRouterHook.UseSubmitImpl);
|
|
696
|
-
let
|
|
719
|
+
let {
|
|
720
|
+
basename
|
|
721
|
+
} = React.useContext(UNSAFE_NavigationContext);
|
|
722
|
+
let currentRouteId = UNSAFE_useRouteId();
|
|
697
723
|
return React.useCallback(function (target, options) {
|
|
698
724
|
if (options === void 0) {
|
|
699
725
|
options = {};
|
|
@@ -704,14 +730,13 @@ function useSubmitImpl(fetcherKey, routeId) {
|
|
|
704
730
|
}
|
|
705
731
|
|
|
706
732
|
let {
|
|
733
|
+
action,
|
|
707
734
|
method,
|
|
708
735
|
encType,
|
|
709
|
-
formData
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
let href = url.pathname + url.search;
|
|
736
|
+
formData
|
|
737
|
+
} = getFormSubmissionInfo(target, options, basename); // Base options shared between fetch() and navigate()
|
|
738
|
+
|
|
713
739
|
let opts = {
|
|
714
|
-
replace: options.replace,
|
|
715
740
|
preventScrollReset: options.preventScrollReset,
|
|
716
741
|
formData,
|
|
717
742
|
formMethod: method,
|
|
@@ -719,13 +744,18 @@ function useSubmitImpl(fetcherKey, routeId) {
|
|
|
719
744
|
};
|
|
720
745
|
|
|
721
746
|
if (fetcherKey) {
|
|
722
|
-
!(
|
|
723
|
-
router.fetch(fetcherKey,
|
|
747
|
+
!(fetcherRouteId != null) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No routeId available for useFetcher()") : UNSAFE_invariant(false) : void 0;
|
|
748
|
+
router.fetch(fetcherKey, fetcherRouteId, action, opts);
|
|
724
749
|
} else {
|
|
725
|
-
router.navigate(
|
|
750
|
+
router.navigate(action, _extends({}, opts, {
|
|
751
|
+
replace: options.replace,
|
|
752
|
+
fromRouteId: currentRouteId
|
|
753
|
+
}));
|
|
726
754
|
}
|
|
727
|
-
}, [
|
|
728
|
-
}
|
|
755
|
+
}, [router, basename, fetcherKey, fetcherRouteId, currentRouteId]);
|
|
756
|
+
} // v7: Eventually we should deprecate this entirely in favor of using the
|
|
757
|
+
// router method directly?
|
|
758
|
+
|
|
729
759
|
|
|
730
760
|
function useFormAction(action, _temp2) {
|
|
731
761
|
let {
|
|
@@ -836,7 +866,7 @@ function useFetcher() {
|
|
|
836
866
|
// fetcher is no longer around.
|
|
837
867
|
return () => {
|
|
838
868
|
if (!router) {
|
|
839
|
-
console.warn("No
|
|
869
|
+
console.warn("No router available to clean up from useFetcher()");
|
|
840
870
|
return;
|
|
841
871
|
}
|
|
842
872
|
|