react-router-dom-v5-compat 6.4.0-pre.8 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -42
- package/dist/index.js +87 -50
- package/dist/index.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/react-router-dom/dom.d.ts +7 -0
- package/dist/react-router-dom/index.d.ts +39 -28
- package/dist/umd/react-router-dom-v5-compat.development.js +90 -50
- 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 +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,46 +1,8 @@
|
|
|
1
1
|
# react-router-dom-v5-compat
|
|
2
2
|
|
|
3
|
-
## 6.4.0
|
|
3
|
+
## 6.4.0
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Updated dependencies**
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
- react-router-dom@6.4.0-pre.8
|
|
10
|
-
|
|
11
|
-
## 6.4.0-pre.7
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- Updated dependencies
|
|
16
|
-
- `react-router@6.4.0-pre.7`
|
|
17
|
-
- `react-router-dom@6.4.0-pre.7`
|
|
18
|
-
|
|
19
|
-
## 6.4.0-pre.6
|
|
20
|
-
|
|
21
|
-
### Patch Changes
|
|
22
|
-
|
|
23
|
-
- Fix `react-router-dom` peer dependency version
|
|
24
|
-
- Updated dependencies
|
|
25
|
-
- `react-router@6.4.0-pre.6`
|
|
26
|
-
- `react-router-dom@6.4.0-pre.6`
|
|
27
|
-
|
|
28
|
-
## 6.4.0-pre.5
|
|
29
|
-
|
|
30
|
-
### Patch Changes
|
|
31
|
-
|
|
32
|
-
- Updated dependencies
|
|
33
|
-
- `react-router@6.4.0-pre.5`
|
|
34
|
-
- `react-router-dom@6.4.0-pre.5`
|
|
35
|
-
|
|
36
|
-
## 6.4.0-pre.4
|
|
37
|
-
|
|
38
|
-
### Patch Changes
|
|
39
|
-
|
|
40
|
-
- Fix missing `dist` files
|
|
41
|
-
|
|
42
|
-
## 6.4.0-pre.3
|
|
43
|
-
|
|
44
|
-
### Patch Changes
|
|
45
|
-
|
|
46
|
-
- Updated dependencies
|
|
7
|
+
- react-router-dom@6.4.0
|
|
8
|
+
- react-router@6.4.0
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router DOM v5 Compat v6.4.0
|
|
2
|
+
* React Router DOM v5 Compat v6.4.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -144,10 +144,11 @@ function getFormSubmissionInfo(target, defaultAction, options) {
|
|
|
144
144
|
method = options.method || target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
|
|
145
145
|
action = options.action || target.getAttribute("formaction") || form.getAttribute("action") || defaultAction;
|
|
146
146
|
encType = options.encType || target.getAttribute("formenctype") || form.getAttribute("enctype") || defaultEncType;
|
|
147
|
-
formData = new FormData(form); // Include name + value from a <button
|
|
147
|
+
formData = new FormData(form); // Include name + value from a <button>, appending in case the button name
|
|
148
|
+
// matches an existing input name
|
|
148
149
|
|
|
149
150
|
if (target.name) {
|
|
150
|
-
formData.
|
|
151
|
+
formData.append(target.name, target.value);
|
|
151
152
|
}
|
|
152
153
|
} else if (isHtmlElement(target)) {
|
|
153
154
|
throw new Error("Cannot submit element that is not <form>, <button>, or " + "<input type=\"submit|image\">");
|
|
@@ -186,19 +187,19 @@ function getFormSubmissionInfo(target, defaultAction, options) {
|
|
|
186
187
|
};
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
const _excluded = ["onClick", "reloadDocument", "replace", "state", "target", "to", "
|
|
190
|
+
const _excluded = ["onClick", "relative", "reloadDocument", "replace", "state", "target", "to", "preventScrollReset"],
|
|
190
191
|
_excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "children"],
|
|
191
|
-
_excluded3 = ["replace", "method", "action", "onSubmit", "fetcherKey", "routeId"];
|
|
192
|
+
_excluded3 = ["reloadDocument", "replace", "method", "action", "onSubmit", "fetcherKey", "routeId", "relative"];
|
|
192
193
|
/**
|
|
193
194
|
* A `<Router>` for use in web browsers. Provides the cleanest URLs.
|
|
194
195
|
*/
|
|
195
196
|
|
|
196
|
-
function BrowserRouter(
|
|
197
|
+
function BrowserRouter(_ref) {
|
|
197
198
|
let {
|
|
198
199
|
basename,
|
|
199
200
|
children,
|
|
200
201
|
window
|
|
201
|
-
} =
|
|
202
|
+
} = _ref;
|
|
202
203
|
let historyRef = React.useRef();
|
|
203
204
|
|
|
204
205
|
if (historyRef.current == null) {
|
|
@@ -227,12 +228,12 @@ function BrowserRouter(_ref3) {
|
|
|
227
228
|
* portion of the URL so it is not sent to the server.
|
|
228
229
|
*/
|
|
229
230
|
|
|
230
|
-
function HashRouter(
|
|
231
|
+
function HashRouter(_ref2) {
|
|
231
232
|
let {
|
|
232
233
|
basename,
|
|
233
234
|
children,
|
|
234
235
|
window
|
|
235
|
-
} =
|
|
236
|
+
} = _ref2;
|
|
236
237
|
let historyRef = React.useRef();
|
|
237
238
|
|
|
238
239
|
if (historyRef.current == null) {
|
|
@@ -263,12 +264,12 @@ function HashRouter(_ref4) {
|
|
|
263
264
|
* version of the history library that React Router uses internally.
|
|
264
265
|
*/
|
|
265
266
|
|
|
266
|
-
function HistoryRouter(
|
|
267
|
+
function HistoryRouter(_ref3) {
|
|
267
268
|
let {
|
|
268
269
|
basename,
|
|
269
270
|
children,
|
|
270
271
|
history
|
|
271
|
-
} =
|
|
272
|
+
} = _ref3;
|
|
272
273
|
const [state, setState] = React.useState({
|
|
273
274
|
action: history.action,
|
|
274
275
|
location: history.location
|
|
@@ -290,30 +291,34 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
290
291
|
* The public API for rendering a history-aware <a>.
|
|
291
292
|
*/
|
|
292
293
|
|
|
293
|
-
const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(
|
|
294
|
+
const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref4, ref) {
|
|
294
295
|
let {
|
|
295
296
|
onClick,
|
|
297
|
+
relative,
|
|
296
298
|
reloadDocument,
|
|
297
299
|
replace,
|
|
298
300
|
state,
|
|
299
301
|
target,
|
|
300
302
|
to,
|
|
301
|
-
|
|
302
|
-
} =
|
|
303
|
-
rest = _objectWithoutPropertiesLoose(
|
|
303
|
+
preventScrollReset
|
|
304
|
+
} = _ref4,
|
|
305
|
+
rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
|
|
304
306
|
|
|
305
|
-
let href = useHref(to
|
|
307
|
+
let href = useHref(to, {
|
|
308
|
+
relative
|
|
309
|
+
});
|
|
306
310
|
let internalOnClick = useLinkClickHandler(to, {
|
|
307
311
|
replace,
|
|
308
312
|
state,
|
|
309
313
|
target,
|
|
310
|
-
|
|
314
|
+
preventScrollReset,
|
|
315
|
+
relative
|
|
311
316
|
});
|
|
312
317
|
|
|
313
318
|
function handleClick(event) {
|
|
314
319
|
if (onClick) onClick(event);
|
|
315
320
|
|
|
316
|
-
if (!event.defaultPrevented
|
|
321
|
+
if (!event.defaultPrevented) {
|
|
317
322
|
internalOnClick(event);
|
|
318
323
|
}
|
|
319
324
|
}
|
|
@@ -323,7 +328,7 @@ const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref6, ref) {
|
|
|
323
328
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
324
329
|
React.createElement("a", _extends({}, rest, {
|
|
325
330
|
href: href,
|
|
326
|
-
onClick: handleClick,
|
|
331
|
+
onClick: reloadDocument ? onClick : handleClick,
|
|
327
332
|
ref: ref,
|
|
328
333
|
target: target
|
|
329
334
|
}))
|
|
@@ -338,7 +343,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
338
343
|
*/
|
|
339
344
|
|
|
340
345
|
|
|
341
|
-
const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(
|
|
346
|
+
const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref5, ref) {
|
|
342
347
|
let {
|
|
343
348
|
"aria-current": ariaCurrentProp = "page",
|
|
344
349
|
caseSensitive = false,
|
|
@@ -347,8 +352,8 @@ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref7, ref
|
|
|
347
352
|
style: styleProp,
|
|
348
353
|
to,
|
|
349
354
|
children
|
|
350
|
-
} =
|
|
351
|
-
rest = _objectWithoutPropertiesLoose(
|
|
355
|
+
} = _ref5,
|
|
356
|
+
rest = _objectWithoutPropertiesLoose(_ref5, _excluded2);
|
|
352
357
|
|
|
353
358
|
let path = useResolvedPath(to);
|
|
354
359
|
let match = useMatch({
|
|
@@ -420,20 +425,24 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
420
425
|
Form.displayName = "Form";
|
|
421
426
|
}
|
|
422
427
|
|
|
423
|
-
const FormImpl = /*#__PURE__*/React.forwardRef((
|
|
428
|
+
const FormImpl = /*#__PURE__*/React.forwardRef((_ref6, forwardedRef) => {
|
|
424
429
|
let {
|
|
430
|
+
reloadDocument,
|
|
425
431
|
replace,
|
|
426
432
|
method = defaultMethod,
|
|
427
|
-
action
|
|
433
|
+
action,
|
|
428
434
|
onSubmit,
|
|
429
435
|
fetcherKey,
|
|
430
|
-
routeId
|
|
431
|
-
|
|
432
|
-
|
|
436
|
+
routeId,
|
|
437
|
+
relative
|
|
438
|
+
} = _ref6,
|
|
439
|
+
props = _objectWithoutPropertiesLoose(_ref6, _excluded3);
|
|
433
440
|
|
|
434
441
|
let submit = useSubmitImpl(fetcherKey, routeId);
|
|
435
442
|
let formMethod = method.toLowerCase() === "get" ? "get" : "post";
|
|
436
|
-
let formAction = useFormAction(action
|
|
443
|
+
let formAction = useFormAction(action, {
|
|
444
|
+
relative
|
|
445
|
+
});
|
|
437
446
|
|
|
438
447
|
let submitHandler = event => {
|
|
439
448
|
onSubmit && onSubmit(event);
|
|
@@ -442,7 +451,8 @@ const FormImpl = /*#__PURE__*/React.forwardRef((_ref8, forwardedRef) => {
|
|
|
442
451
|
let submitter = event.nativeEvent.submitter;
|
|
443
452
|
submit(submitter || event.currentTarget, {
|
|
444
453
|
method,
|
|
445
|
-
replace
|
|
454
|
+
replace,
|
|
455
|
+
relative
|
|
446
456
|
});
|
|
447
457
|
};
|
|
448
458
|
|
|
@@ -450,7 +460,7 @@ const FormImpl = /*#__PURE__*/React.forwardRef((_ref8, forwardedRef) => {
|
|
|
450
460
|
ref: forwardedRef,
|
|
451
461
|
method: formMethod,
|
|
452
462
|
action: formAction,
|
|
453
|
-
onSubmit: submitHandler
|
|
463
|
+
onSubmit: reloadDocument ? onSubmit : submitHandler
|
|
454
464
|
}, props));
|
|
455
465
|
});
|
|
456
466
|
|
|
@@ -475,24 +485,28 @@ function useLinkClickHandler(to, _temp) {
|
|
|
475
485
|
target,
|
|
476
486
|
replace: replaceProp,
|
|
477
487
|
state,
|
|
478
|
-
|
|
488
|
+
preventScrollReset,
|
|
489
|
+
relative
|
|
479
490
|
} = _temp === void 0 ? {} : _temp;
|
|
480
491
|
let navigate = useNavigate();
|
|
481
492
|
let location = useLocation();
|
|
482
|
-
let path = useResolvedPath(to
|
|
493
|
+
let path = useResolvedPath(to, {
|
|
494
|
+
relative
|
|
495
|
+
});
|
|
483
496
|
return React.useCallback(event => {
|
|
484
497
|
if (shouldProcessLinkClick(event, target)) {
|
|
485
498
|
event.preventDefault(); // If the URL hasn't changed, a regular <a> will do a replace instead of
|
|
486
|
-
// a push, so do the same here unless the replace prop is
|
|
499
|
+
// a push, so do the same here unless the replace prop is explicitly set
|
|
487
500
|
|
|
488
501
|
let replace = replaceProp !== undefined ? replaceProp : createPath(location) === createPath(path);
|
|
489
502
|
navigate(to, {
|
|
490
503
|
replace,
|
|
491
504
|
state,
|
|
492
|
-
|
|
505
|
+
preventScrollReset,
|
|
506
|
+
relative
|
|
493
507
|
});
|
|
494
508
|
}
|
|
495
|
-
}, [location, navigate, path, replaceProp, state, target, to,
|
|
509
|
+
}, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative]);
|
|
496
510
|
}
|
|
497
511
|
/**
|
|
498
512
|
* A convenient wrapper for reading and writing search parameters via the
|
|
@@ -513,15 +527,17 @@ function useSearchParams(defaultInit) {
|
|
|
513
527
|
}
|
|
514
528
|
|
|
515
529
|
function useSubmitImpl(fetcherKey, routeId) {
|
|
516
|
-
let
|
|
530
|
+
let dataRouterContext = React.useContext(UNSAFE_DataRouterContext);
|
|
531
|
+
!dataRouterContext ? process.env.NODE_ENV !== "production" ? invariant(false, "useSubmitImpl must be used within a Data Router") : invariant(false) : void 0;
|
|
532
|
+
let {
|
|
533
|
+
router
|
|
534
|
+
} = dataRouterContext;
|
|
517
535
|
let defaultAction = useFormAction();
|
|
518
536
|
return React.useCallback(function (target, options) {
|
|
519
537
|
if (options === void 0) {
|
|
520
538
|
options = {};
|
|
521
539
|
}
|
|
522
540
|
|
|
523
|
-
!(router != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "useSubmit() must be used within a <DataRouter>") : invariant(false) : void 0;
|
|
524
|
-
|
|
525
541
|
if (typeof document === "undefined") {
|
|
526
542
|
throw new Error("You are calling submit during the server render. " + "Try calling submit within a `useEffect` or callback instead.");
|
|
527
543
|
}
|
|
@@ -549,24 +565,45 @@ function useSubmitImpl(fetcherKey, routeId) {
|
|
|
549
565
|
}, [defaultAction, router, fetcherKey, routeId]);
|
|
550
566
|
}
|
|
551
567
|
|
|
552
|
-
function useFormAction(action) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
568
|
+
function useFormAction(action, _temp2) {
|
|
569
|
+
let {
|
|
570
|
+
relative
|
|
571
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
557
572
|
let routeContext = React.useContext(UNSAFE_RouteContext);
|
|
558
573
|
!routeContext ? process.env.NODE_ENV !== "production" ? invariant(false, "useFormAction must be used inside a RouteContext") : invariant(false) : void 0;
|
|
559
574
|
let [match] = routeContext.matches.slice(-1);
|
|
560
|
-
let
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
575
|
+
let resolvedAction = action != null ? action : ".";
|
|
576
|
+
let path = useResolvedPath(resolvedAction, {
|
|
577
|
+
relative
|
|
578
|
+
}); // Previously we set the default action to ".". The problem with this is that
|
|
579
|
+
// `useResolvedPath(".")` excludes search params and the hash of the resolved
|
|
580
|
+
// URL. This is the intended behavior of when "." is specifically provided as
|
|
581
|
+
// the form action, but inconsistent w/ browsers when the action is omitted.
|
|
582
|
+
// https://github.com/remix-run/remix/issues/927
|
|
583
|
+
|
|
584
|
+
let location = useLocation();
|
|
585
|
+
|
|
586
|
+
if (action == null) {
|
|
587
|
+
// Safe to write to these directly here since if action was undefined, we
|
|
588
|
+
// would have called useResolvedPath(".") which will never include a search
|
|
589
|
+
// or hash
|
|
590
|
+
path.search = location.search;
|
|
591
|
+
path.hash = location.hash; // When grabbing search params from the URL, remove the automatically
|
|
592
|
+
// inserted ?index param so we match the useResolvedPath search behavior
|
|
593
|
+
// which would not include ?index
|
|
594
|
+
|
|
595
|
+
if (match.route.index) {
|
|
596
|
+
let params = new URLSearchParams(path.search);
|
|
597
|
+
params.delete("index");
|
|
598
|
+
path.search = params.toString() ? "?" + params.toString() : "";
|
|
599
|
+
}
|
|
600
|
+
}
|
|
564
601
|
|
|
565
|
-
if (action === "." && match.route.index) {
|
|
566
|
-
search = search ? search.replace(/^\?/, "?index&") : "?index";
|
|
602
|
+
if ((!action || action === ".") && match.route.index) {
|
|
603
|
+
path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
|
567
604
|
}
|
|
568
605
|
|
|
569
|
-
return
|
|
606
|
+
return createPath(path);
|
|
570
607
|
}
|
|
571
608
|
////////////////////////////////////////////////////////////////////////////////
|
|
572
609
|
//#region Utils
|