react-router-dom-v5-compat 6.2.2 → 6.4.0-pre.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * React Router DOM v5 Compat v6.2.2
2
+ * React Router DOM v5 Compat v6.4.0-pre.2
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -9,10 +9,10 @@
9
9
  * @license MIT
10
10
  */
11
11
  (function (global, factory) {
12
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('history'), require('react-router'), require('react-router-dom')) :
13
- typeof define === 'function' && define.amd ? define(['exports', 'react', 'history', 'react-router', 'react-router-dom'], factory) :
14
- (global = global || self, factory(global.ReactRouterDOMv5Compat = {}, global.React, global.HistoryLibrary, global.ReactRouter, global.ReactRouterDOM));
15
- }(this, (function (exports, React, history, reactRouter, reactRouterDom) { 'use strict';
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-router'), require('@remix-run/router'), require('history'), require('react-router-dom')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-router', '@remix-run/router', 'history', 'react-router-dom'], factory) :
14
+ (global = global || self, factory(global.ReactRouterDOMv5Compat = {}, global.React, global.ReactRouter, global.Router, global.HistoryLibrary, global.ReactRouterDOM));
15
+ }(this, (function (exports, React, reactRouter, router, history, reactRouterDom) { 'use strict';
16
16
 
17
17
  function _extends() {
18
18
  _extends = Object.assign || function (target) {
@@ -47,56 +47,190 @@
47
47
  return target;
48
48
  }
49
49
 
50
- const _excluded = ["onClick", "reloadDocument", "replace", "state", "target", "to"],
51
- _excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "children"];
50
+ const defaultMethod = "get";
51
+ const defaultEncType = "application/x-www-form-urlencoded";
52
+ function isHtmlElement(object) {
53
+ return object != null && typeof object.tagName === "string";
54
+ }
55
+ function isButtonElement(object) {
56
+ return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
57
+ }
58
+ function isFormElement(object) {
59
+ return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
60
+ }
61
+ function isInputElement(object) {
62
+ return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
63
+ }
52
64
 
53
- function warning(cond, message) {
54
- if (!cond) {
55
- // eslint-disable-next-line no-console
56
- if (typeof console !== "undefined") console.warn(message);
65
+ function isModifiedEvent(event) {
66
+ return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
67
+ }
57
68
 
58
- try {
59
- // Welcome to debugging React Router!
60
- //
61
- // This error is thrown as a convenience so you can more easily
62
- // find the source for a warning that appears in the console by
63
- // enabling "pause on exceptions" in your JavaScript debugger.
64
- throw new Error(message); // eslint-disable-next-line no-empty
65
- } catch (e) {}
69
+ function shouldProcessLinkClick(event, target) {
70
+ return event.button === 0 && ( // Ignore everything but left clicks
71
+ !target || target === "_self") && // Let browser handle "target=_blank" etc.
72
+ !isModifiedEvent(event) // Ignore clicks with modifier keys
73
+ ;
74
+ }
75
+
76
+ /**
77
+ * Creates a URLSearchParams object using the given initializer.
78
+ *
79
+ * This is identical to `new URLSearchParams(init)` except it also
80
+ * supports arrays as values in the object form of the initializer
81
+ * instead of just strings. This is convenient when you need multiple
82
+ * values for a given key, but don't want to use an array initializer.
83
+ *
84
+ * For example, instead of:
85
+ *
86
+ * let searchParams = new URLSearchParams([
87
+ * ['sort', 'name'],
88
+ * ['sort', 'price']
89
+ * ]);
90
+ *
91
+ * you can do:
92
+ *
93
+ * let searchParams = createSearchParams({
94
+ * sort: ['name', 'price']
95
+ * });
96
+ */
97
+ function createSearchParams(init) {
98
+ if (init === void 0) {
99
+ init = "";
66
100
  }
67
- } ////////////////////////////////////////////////////////////////////////////////
68
- // COMPONENTS
69
- ////////////////////////////////////////////////////////////////////////////////
101
+
102
+ return new URLSearchParams(typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo, key) => {
103
+ let value = init[key];
104
+ return memo.concat(Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]);
105
+ }, []));
106
+ }
107
+ function getSearchParamsForLocation(locationSearch, defaultSearchParams) {
108
+ let searchParams = createSearchParams(locationSearch);
109
+
110
+ for (let key of defaultSearchParams.keys()) {
111
+ if (!searchParams.has(key)) {
112
+ defaultSearchParams.getAll(key).forEach(value => {
113
+ searchParams.append(key, value);
114
+ });
115
+ }
116
+ }
117
+
118
+ return searchParams;
119
+ }
120
+ function getFormSubmissionInfo(target, defaultAction, options) {
121
+ let method;
122
+ let action;
123
+ let encType;
124
+ let formData;
125
+
126
+ if (isFormElement(target)) {
127
+ let submissionTrigger = options.submissionTrigger;
128
+ method = options.method || target.getAttribute("method") || defaultMethod;
129
+ action = options.action || target.getAttribute("action") || defaultAction;
130
+ encType = options.encType || target.getAttribute("enctype") || defaultEncType;
131
+ formData = new FormData(target);
132
+
133
+ if (submissionTrigger && submissionTrigger.name) {
134
+ formData.append(submissionTrigger.name, submissionTrigger.value);
135
+ }
136
+ } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
137
+ let form = target.form;
138
+
139
+ if (form == null) {
140
+ throw new Error("Cannot submit a <button> or <input type=\"submit\"> without a <form>");
141
+ } // <button>/<input type="submit"> may override attributes of <form>
142
+
143
+
144
+ method = options.method || target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
145
+ action = options.action || target.getAttribute("formaction") || form.getAttribute("action") || defaultAction;
146
+ encType = options.encType || target.getAttribute("formenctype") || form.getAttribute("enctype") || defaultEncType;
147
+ formData = new FormData(form); // Include name + value from a <button>
148
+
149
+ if (target.name) {
150
+ formData.set(target.name, target.value);
151
+ }
152
+ } else if (isHtmlElement(target)) {
153
+ throw new Error("Cannot submit element that is not <form>, <button>, or " + "<input type=\"submit|image\">");
154
+ } else {
155
+ method = options.method || defaultMethod;
156
+ action = options.action || defaultAction;
157
+ encType = options.encType || defaultEncType;
158
+
159
+ if (target instanceof FormData) {
160
+ formData = target;
161
+ } else {
162
+ formData = new FormData();
163
+
164
+ if (target instanceof URLSearchParams) {
165
+ for (let [name, value] of target) {
166
+ formData.append(name, value);
167
+ }
168
+ } else if (target != null) {
169
+ for (let name of Object.keys(target)) {
170
+ formData.append(name, target[name]);
171
+ }
172
+ }
173
+ }
174
+ }
175
+
176
+ let {
177
+ protocol,
178
+ host
179
+ } = window.location;
180
+ let url = new URL(action, protocol + "//" + host);
181
+
182
+ if (method.toLowerCase() === "get") {
183
+ for (let [name, value] of formData) {
184
+ if (typeof value === "string") {
185
+ url.searchParams.append(name, value);
186
+ } else {
187
+ throw new Error("Cannot submit binary form data using GET");
188
+ }
189
+ }
190
+ }
191
+
192
+ return {
193
+ url,
194
+ method,
195
+ encType,
196
+ formData
197
+ };
198
+ }
199
+
200
+ const _excluded = ["onClick", "reloadDocument", "replace", "state", "target", "to", "resetScroll"],
201
+ _excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "children"],
202
+ _excluded3 = ["replace", "method", "action", "onSubmit", "fetcherKey"];
70
203
 
71
204
  /**
72
205
  * A `<Router>` for use in web browsers. Provides the cleanest URLs.
73
206
  */
74
- function BrowserRouter(_ref) {
207
+ function BrowserRouter(_ref3) {
75
208
  let {
76
209
  basename,
77
210
  children,
78
211
  window
79
- } = _ref;
212
+ } = _ref3;
80
213
  let historyRef = React.useRef();
81
214
 
82
215
  if (historyRef.current == null) {
83
- historyRef.current = history.createBrowserHistory({
84
- window
216
+ historyRef.current = router.createBrowserHistory({
217
+ window,
218
+ v5Compat: true
85
219
  });
86
220
  }
87
221
 
88
- let history$1 = historyRef.current;
222
+ let history = historyRef.current;
89
223
  let [state, setState] = React.useState({
90
- action: history$1.action,
91
- location: history$1.location
224
+ action: history.action,
225
+ location: history.location
92
226
  });
93
- React.useLayoutEffect(() => history$1.listen(setState), [history$1]);
227
+ React.useLayoutEffect(() => history.listen(setState), [history]);
94
228
  return /*#__PURE__*/React.createElement(reactRouter.Router, {
95
229
  basename: basename,
96
230
  children: children,
97
231
  location: state.location,
98
232
  navigationType: state.action,
99
- navigator: history$1
233
+ navigator: history
100
234
  });
101
235
  }
102
236
 
@@ -104,32 +238,33 @@
104
238
  * A `<Router>` for use in web browsers. Stores the location in the hash
105
239
  * portion of the URL so it is not sent to the server.
106
240
  */
107
- function HashRouter(_ref2) {
241
+ function HashRouter(_ref4) {
108
242
  let {
109
243
  basename,
110
244
  children,
111
245
  window
112
- } = _ref2;
246
+ } = _ref4;
113
247
  let historyRef = React.useRef();
114
248
 
115
249
  if (historyRef.current == null) {
116
- historyRef.current = history.createHashHistory({
117
- window
250
+ historyRef.current = router.createHashHistory({
251
+ window,
252
+ v5Compat: true
118
253
  });
119
254
  }
120
255
 
121
- let history$1 = historyRef.current;
256
+ let history = historyRef.current;
122
257
  let [state, setState] = React.useState({
123
- action: history$1.action,
124
- location: history$1.location
258
+ action: history.action,
259
+ location: history.location
125
260
  });
126
- React.useLayoutEffect(() => history$1.listen(setState), [history$1]);
261
+ React.useLayoutEffect(() => history.listen(setState), [history]);
127
262
  return /*#__PURE__*/React.createElement(reactRouter.Router, {
128
263
  basename: basename,
129
264
  children: children,
130
265
  location: state.location,
131
266
  navigationType: state.action,
132
- navigator: history$1
267
+ navigator: history
133
268
  });
134
269
  }
135
270
 
@@ -139,12 +274,12 @@
139
274
  * two versions of the history library to your bundles unless you use the same
140
275
  * version of the history library that React Router uses internally.
141
276
  */
142
- function HistoryRouter(_ref3) {
277
+ function HistoryRouter(_ref5) {
143
278
  let {
144
279
  basename,
145
280
  children,
146
281
  history
147
- } = _ref3;
282
+ } = _ref5;
148
283
  const [state, setState] = React.useState({
149
284
  action: history.action,
150
285
  location: history.location
@@ -163,29 +298,27 @@
163
298
  HistoryRouter.displayName = "unstable_HistoryRouter";
164
299
  }
165
300
 
166
- function isModifiedEvent(event) {
167
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
168
- }
169
-
170
301
  /**
171
302
  * The public API for rendering a history-aware <a>.
172
303
  */
173
- const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref4, ref) {
304
+ const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref6, ref) {
174
305
  let {
175
306
  onClick,
176
307
  reloadDocument,
177
308
  replace = false,
178
309
  state,
179
310
  target,
180
- to
181
- } = _ref4,
182
- rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
311
+ to,
312
+ resetScroll
313
+ } = _ref6,
314
+ rest = _objectWithoutPropertiesLoose(_ref6, _excluded);
183
315
 
184
316
  let href = reactRouter.useHref(to);
185
317
  let internalOnClick = useLinkClickHandler(to, {
186
318
  replace,
187
319
  state,
188
- target
320
+ target,
321
+ resetScroll
189
322
  });
190
323
 
191
324
  function handleClick(event) {
@@ -215,7 +348,7 @@
215
348
  /**
216
349
  * A <Link> wrapper that knows if it's "active" or not.
217
350
  */
218
- const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref5, ref) {
351
+ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref7, ref) {
219
352
  let {
220
353
  "aria-current": ariaCurrentProp = "page",
221
354
  caseSensitive = false,
@@ -224,26 +357,32 @@
224
357
  style: styleProp,
225
358
  to,
226
359
  children
227
- } = _ref5,
228
- rest = _objectWithoutPropertiesLoose(_ref5, _excluded2);
360
+ } = _ref7,
361
+ rest = _objectWithoutPropertiesLoose(_ref7, _excluded2);
229
362
 
230
- let location = reactRouter.useLocation();
231
363
  let path = reactRouter.useResolvedPath(to);
232
- let locationPathname = location.pathname;
233
- let toPathname = path.pathname;
234
-
235
- if (!caseSensitive) {
236
- locationPathname = locationPathname.toLowerCase();
237
- toPathname = toPathname.toLowerCase();
238
- }
239
-
240
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(toPathname.length) === "/";
364
+ let match = reactRouter.useMatch({
365
+ path: path.pathname,
366
+ end,
367
+ caseSensitive
368
+ });
369
+ let routerState = React.useContext(reactRouter.UNSAFE_DataRouterStateContext);
370
+ let nextLocation = routerState == null ? void 0 : routerState.navigation.location;
371
+ let nextPath = reactRouter.useResolvedPath(nextLocation || "");
372
+ let nextMatch = React.useMemo(() => nextLocation ? router.matchPath({
373
+ path: path.pathname,
374
+ end,
375
+ caseSensitive
376
+ }, nextPath.pathname) : null, [nextLocation, path.pathname, caseSensitive, end, nextPath.pathname]);
377
+ let isPending = nextMatch != null;
378
+ let isActive = match != null;
241
379
  let ariaCurrent = isActive ? ariaCurrentProp : undefined;
242
380
  let className;
243
381
 
244
382
  if (typeof classNameProp === "function") {
245
383
  className = classNameProp({
246
- isActive
384
+ isActive,
385
+ isPending
247
386
  });
248
387
  } else {
249
388
  // If the className prop is not a function, we use a default `active`
@@ -251,11 +390,12 @@
251
390
  // value for `activeClassName`, but we are removing that API and can still
252
391
  // use the old default behavior for a cleaner upgrade path and keep the
253
392
  // simple styling rules working as they currently do.
254
- className = [classNameProp, isActive ? "active" : null].filter(Boolean).join(" ");
393
+ className = [classNameProp, isActive ? "active" : null, isPending ? "pending" : null].filter(Boolean).join(" ");
255
394
  }
256
395
 
257
396
  let style = typeof styleProp === "function" ? styleProp({
258
- isActive
397
+ isActive,
398
+ isPending
259
399
  }) : styleProp;
260
400
  return /*#__PURE__*/React.createElement(Link, _extends({}, rest, {
261
401
  "aria-current": ariaCurrent,
@@ -264,14 +404,69 @@
264
404
  style: style,
265
405
  to: to
266
406
  }), typeof children === "function" ? children({
267
- isActive
407
+ isActive,
408
+ isPending
268
409
  }) : children);
269
410
  });
270
411
 
271
412
  {
272
413
  NavLink.displayName = "NavLink";
273
- } ////////////////////////////////////////////////////////////////////////////////
274
- // HOOKS
414
+ }
415
+
416
+ /**
417
+ * A `@remix-run/router`-aware `<form>`. It behaves like a normal form except
418
+ * that the interaction with the server is with `fetch` instead of new document
419
+ * requests, allowing components to add nicer UX to the page as the form is
420
+ * submitted and returns with data.
421
+ */
422
+ const Form = /*#__PURE__*/React.forwardRef((props, ref) => {
423
+ return /*#__PURE__*/React.createElement(FormImpl, _extends({}, props, {
424
+ ref: ref
425
+ }));
426
+ });
427
+
428
+ {
429
+ Form.displayName = "Form";
430
+ }
431
+
432
+ const FormImpl = /*#__PURE__*/React.forwardRef((_ref8, forwardedRef) => {
433
+ let {
434
+ replace,
435
+ method = defaultMethod,
436
+ action = ".",
437
+ onSubmit,
438
+ fetcherKey
439
+ } = _ref8,
440
+ props = _objectWithoutPropertiesLoose(_ref8, _excluded3);
441
+
442
+ let submit = useSubmitImpl(fetcherKey);
443
+ let formMethod = method.toLowerCase() === "get" ? "get" : "post";
444
+ let formAction = useFormAction(action);
445
+
446
+ let submitHandler = event => {
447
+ onSubmit && onSubmit(event);
448
+ if (event.defaultPrevented) return;
449
+ event.preventDefault();
450
+ let submitter = event.nativeEvent.submitter;
451
+ submit(submitter || event.currentTarget, {
452
+ method,
453
+ replace
454
+ });
455
+ };
456
+
457
+ return /*#__PURE__*/React.createElement("form", _extends({
458
+ ref: forwardedRef,
459
+ method: formMethod,
460
+ action: formAction,
461
+ onSubmit: submitHandler
462
+ }, props));
463
+ });
464
+
465
+ {
466
+ Form.displayName = "Form";
467
+ }
468
+ ////////////////////////////////////////////////////////////////////////////////
469
+ //#region Hooks
275
470
  ////////////////////////////////////////////////////////////////////////////////
276
471
 
277
472
  /**
@@ -285,26 +480,32 @@
285
480
  let {
286
481
  target,
287
482
  replace: replaceProp,
288
- state
483
+ state,
484
+ resetScroll
289
485
  } = _temp === void 0 ? {} : _temp;
290
486
  let navigate = reactRouter.useNavigate();
291
487
  let location = reactRouter.useLocation();
292
488
  let path = reactRouter.useResolvedPath(to);
293
489
  return React.useCallback(event => {
294
- if (event.button === 0 && ( // Ignore everything but left clicks
295
- !target || target === "_self") && // Let browser handle "target=_blank" etc.
296
- !isModifiedEvent(event) // Ignore clicks with modifier keys
297
- ) {
490
+ if (shouldProcessLinkClick(event, target)) {
298
491
  event.preventDefault(); // If the URL hasn't changed, a regular <a> will do a replace instead of
299
492
  // a push, so do the same here.
300
493
 
301
494
  let replace = !!replaceProp || reactRouter.createPath(location) === reactRouter.createPath(path);
495
+ let newState = state;
496
+
497
+ if (resetScroll === false) {
498
+ newState = _extends({}, state, {
499
+ __resetScrollPosition: false
500
+ });
501
+ }
502
+
302
503
  navigate(to, {
303
504
  replace,
304
- state
505
+ state: newState
305
506
  });
306
507
  }
307
- }, [location, navigate, path, replaceProp, state, target, to]);
508
+ }, [location, navigate, path, replaceProp, state, target, to, resetScroll]);
308
509
  }
309
510
  /**
310
511
  * A convenient wrapper for reading and writing search parameters via the
@@ -315,19 +516,7 @@
315
516
  warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params\n\n" + "If you're unsure how to load polyfills, we recommend you check out " + "https://polyfill.io/v3/ which provides some recommendations about how " + "to load polyfills only for users that need them, instead of for every " + "user.") ;
316
517
  let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit));
317
518
  let location = reactRouter.useLocation();
318
- let searchParams = React.useMemo(() => {
319
- let searchParams = createSearchParams(location.search);
320
-
321
- for (let key of defaultSearchParamsRef.current.keys()) {
322
- if (!searchParams.has(key)) {
323
- defaultSearchParamsRef.current.getAll(key).forEach(value => {
324
- searchParams.append(key, value);
325
- });
326
- }
327
- }
328
-
329
- return searchParams;
330
- }, [location.search]);
519
+ let searchParams = React.useMemo(() => getSearchParamsForLocation(location.search, defaultSearchParamsRef.current), [location.search]);
331
520
  let navigate = reactRouter.useNavigate();
332
521
  let setSearchParams = React.useCallback((nextInit, navigateOptions) => {
333
522
  navigate("?" + createSearchParams(nextInit), navigateOptions);
@@ -335,38 +524,96 @@
335
524
  return [searchParams, setSearchParams];
336
525
  }
337
526
 
338
- /**
339
- * Creates a URLSearchParams object using the given initializer.
340
- *
341
- * This is identical to `new URLSearchParams(init)` except it also
342
- * supports arrays as values in the object form of the initializer
343
- * instead of just strings. This is convenient when you need multiple
344
- * values for a given key, but don't want to use an array initializer.
345
- *
346
- * For example, instead of:
347
- *
348
- * let searchParams = new URLSearchParams([
349
- * ['sort', 'name'],
350
- * ['sort', 'price']
351
- * ]);
352
- *
353
- * you can do:
354
- *
355
- * let searchParams = createSearchParams({
356
- * sort: ['name', 'price']
357
- * });
358
- */
359
- function createSearchParams(init) {
360
- if (init === void 0) {
361
- init = "";
527
+ function useSubmitImpl(fetcherKey) {
528
+ let router$1 = React.useContext(reactRouter.UNSAFE_DataRouterContext);
529
+ let defaultAction = useFormAction();
530
+ return React.useCallback(function (target, options) {
531
+ if (options === void 0) {
532
+ options = {};
533
+ }
534
+
535
+ !(router$1 != null) ? router.invariant(false, "useSubmit() must be used within a <DataRouter>") : void 0;
536
+
537
+ if (typeof document === "undefined") {
538
+ throw new Error("You are calling submit during the server render. " + "Try calling submit within a `useEffect` or callback instead.");
539
+ }
540
+
541
+ let {
542
+ method,
543
+ encType,
544
+ formData,
545
+ url
546
+ } = getFormSubmissionInfo(target, defaultAction, options);
547
+ let href = url.pathname + url.search;
548
+ let opts = {
549
+ // If replace is not specified, we'll default to false for GET and
550
+ // true otherwise
551
+ replace: options.replace != null ? options.replace === true : method !== "get",
552
+ formData,
553
+ formMethod: method,
554
+ formEncType: encType
555
+ };
556
+
557
+ if (fetcherKey) {
558
+ router$1.fetch(fetcherKey, href, opts);
559
+ } else {
560
+ router$1.navigate(href, opts);
561
+ }
562
+ }, [defaultAction, router$1, fetcherKey]);
563
+ }
564
+
565
+ function useFormAction(action) {
566
+ if (action === void 0) {
567
+ action = ".";
362
568
  }
363
569
 
364
- return new URLSearchParams(typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo, key) => {
365
- let value = init[key];
366
- return memo.concat(Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]);
367
- }, []));
570
+ let routeContext = React.useContext(reactRouter.UNSAFE_RouteContext);
571
+ !routeContext ? router.invariant(false, "useLoaderData must be used inside a RouteContext") : void 0;
572
+ let [match] = routeContext.matches.slice(-1);
573
+ let {
574
+ pathname,
575
+ search
576
+ } = reactRouter.useResolvedPath(action);
577
+
578
+ if (action === "." && match.route.index) {
579
+ search = search ? search.replace(/^\?/, "?index&") : "?index";
580
+ }
581
+
582
+ return pathname + search;
368
583
  }
584
+ ////////////////////////////////////////////////////////////////////////////////
585
+ //#region Utils
586
+ ////////////////////////////////////////////////////////////////////////////////
587
+
588
+
589
+ function warning(cond, message) {
590
+ if (!cond) {
591
+ // eslint-disable-next-line no-console
592
+ if (typeof console !== "undefined") console.warn(message);
593
+
594
+ try {
595
+ // Welcome to debugging React Router!
596
+ //
597
+ // This error is thrown as a convenience so you can more easily
598
+ // find the source for a warning that appears in the console by
599
+ // enabling "pause on exceptions" in your JavaScript debugger.
600
+ throw new Error(message); // eslint-disable-next-line no-empty
601
+ } catch (e) {}
602
+ }
603
+ } //#endregion
604
+
605
+ // but not worried about that for now.
369
606
 
607
+ function CompatRoute(props) {
608
+ let {
609
+ path
610
+ } = props;
611
+ if (!props.exact) path += "/*";
612
+ return /*#__PURE__*/React.createElement(reactRouter.Routes, null, /*#__PURE__*/React.createElement(reactRouter.Route, {
613
+ path: path,
614
+ element: /*#__PURE__*/React.createElement(reactRouterDom.Route, props)
615
+ }));
616
+ }
370
617
  function CompatRouter(_ref) {
371
618
  let {
372
619
  children
@@ -376,7 +623,7 @@
376
623
  location: history.location,
377
624
  action: history.action
378
625
  }));
379
- React.useEffect(() => {
626
+ React.useLayoutEffect(() => {
380
627
  history.listen((location, action) => setState({
381
628
  location,
382
629
  action
@@ -393,7 +640,7 @@
393
640
  }
394
641
 
395
642
  /**
396
- * A <Router> that may not transition to any other location. This is useful
643
+ * A <Router> that may not navigate to any other location. This is useful
397
644
  * on the server where there is no stateful UI.
398
645
  */
399
646
  function StaticRouter(_ref2) {
@@ -626,6 +873,7 @@
626
873
  }
627
874
  });
628
875
  exports.BrowserRouter = BrowserRouter;
876
+ exports.CompatRoute = CompatRoute;
629
877
  exports.CompatRouter = CompatRouter;
630
878
  exports.HashRouter = HashRouter;
631
879
  exports.Link = Link;