@remix-run/router 1.23.2 → 1.23.4

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
- * @remix-run/router v1.23.2
2
+ * @remix-run/router v1.23.4
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -15,18 +15,13 @@
15
15
  })(this, (function (exports) { 'use strict';
16
16
 
17
17
  function _extends() {
18
- _extends = Object.assign ? Object.assign.bind() : function (target) {
19
- for (var i = 1; i < arguments.length; i++) {
20
- var source = arguments[i];
21
- for (var key in source) {
22
- if (Object.prototype.hasOwnProperty.call(source, key)) {
23
- target[key] = source[key];
24
- }
25
- }
18
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
19
+ for (var e = 1; e < arguments.length; e++) {
20
+ var t = arguments[e];
21
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
26
22
  }
27
- return target;
28
- };
29
- return _extends.apply(this, arguments);
23
+ return n;
24
+ }, _extends.apply(null, arguments);
30
25
  }
31
26
 
32
27
  ////////////////////////////////////////////////////////////////////////////////
@@ -37,8 +32,24 @@
37
32
  * Actions represent the type of change to a location value.
38
33
  */
39
34
  let Action = /*#__PURE__*/function (Action) {
35
+ /**
36
+ * A POP indicates a change to an arbitrary index in the history stack, such
37
+ * as a back or forward navigation. It does not describe the direction of the
38
+ * navigation, only that the current index changed.
39
+ *
40
+ * Note: This is the default action for newly created history objects.
41
+ */
40
42
  Action["Pop"] = "POP";
43
+ /**
44
+ * A PUSH indicates a new entry being added to the history stack, such as when
45
+ * a link is clicked and a new page loads. When this happens, all subsequent
46
+ * entries in the stack are lost.
47
+ */
41
48
  Action["Push"] = "PUSH";
49
+ /**
50
+ * A REPLACE indicates the entry at the current index in the history stack
51
+ * being replaced by a new one.
52
+ */
42
53
  Action["Replace"] = "REPLACE";
43
54
  return Action;
44
55
  }({});
@@ -49,21 +60,26 @@
49
60
 
50
61
  // TODO: (v7) Change the Location generic default from `any` to `unknown` and
51
62
  // remove Remix `useLocation` wrapper.
63
+
52
64
  /**
53
65
  * An entry in a history stack. A location contains information about the
54
66
  * URL path, as well as possibly some arbitrary state and a key.
55
67
  */
68
+
56
69
  /**
57
70
  * A change to the current location.
58
71
  */
72
+
59
73
  /**
60
74
  * A function that receives notifications about location changes.
61
75
  */
76
+
62
77
  /**
63
78
  * Describes a location that is the destination of some navigation, either via
64
79
  * `history.push` or `history.replace`. This may be either a URL or the pieces
65
80
  * of a URL path.
66
81
  */
82
+
67
83
  /**
68
84
  * A history is an interface to the navigation stack. The history serves as the
69
85
  * source of truth for the current location, as well as provides a set of
@@ -72,6 +88,7 @@
72
88
  * It is similar to the DOM's `window.history` object, but with a smaller, more
73
89
  * focused API.
74
90
  */
91
+
75
92
  const PopStateEventType = "popstate";
76
93
  //#endregion
77
94
 
@@ -83,11 +100,13 @@
83
100
  * A user-supplied object that describes a location. Used when providing
84
101
  * entries to `createMemoryHistory` via its `initialEntries` option.
85
102
  */
103
+
86
104
  /**
87
105
  * A memory history stores locations in memory. This is useful in stateful
88
106
  * environments where there is no web browser, such as node tests or React
89
107
  * Native.
90
108
  */
109
+
91
110
  /**
92
111
  * Memory history stores the current location in memory. It is designed for use
93
112
  * in stateful non-browser environments like tests and React Native.
@@ -205,6 +224,7 @@
205
224
  *
206
225
  * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
207
226
  */
227
+
208
228
  /**
209
229
  * Browser history stores the location in regular URLs. This is the standard for
210
230
  * most web apps, but it requires some configuration on the server to ensure you
@@ -252,6 +272,7 @@
252
272
  *
253
273
  * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory
254
274
  */
275
+
255
276
  /**
256
277
  * Hash history stores the location in window.location.hash. This makes it ideal
257
278
  * for situations where you don't want to send the location to the server for
@@ -312,6 +333,7 @@
312
333
  /**
313
334
  * @private
314
335
  */
336
+
315
337
  function invariant(value, message) {
316
338
  if (value === false || value === null || typeof value === "undefined") {
317
339
  throw new Error(message);
@@ -611,26 +633,33 @@
611
633
  // TODO: (v7) Change the defaults from any to unknown in and remove Remix wrappers:
612
634
  // ActionFunction, ActionFunctionArgs, LoaderFunction, LoaderFunctionArgs
613
635
  // Also, make them a type alias instead of an interface
636
+
614
637
  /**
615
638
  * Arguments passed to loader functions
616
639
  */
640
+
617
641
  /**
618
642
  * Arguments passed to action functions
619
643
  */
644
+
620
645
  /**
621
646
  * Loaders and actions can return anything except `undefined` (`null` is a
622
647
  * valid return value if there is no data to return). Responses are preferred
623
648
  * and will ease any future migration to Remix
624
649
  */
650
+
625
651
  /**
626
652
  * Route loader function signature
627
653
  */
654
+
628
655
  /**
629
656
  * Route action function signature
630
657
  */
658
+
631
659
  /**
632
660
  * Arguments passed to shouldRevalidate function
633
661
  */
662
+
634
663
  /**
635
664
  * Route shouldRevalidate function signature. This runs after any submission
636
665
  * (navigation or fetcher), so we flatten the navigation/fetcher submission
@@ -638,24 +667,29 @@
638
667
  * or a fetcher, what really matters is the URLs and the formData since loaders
639
668
  * have to re-run based on the data models that were potentially mutated.
640
669
  */
670
+
641
671
  /**
642
672
  * Function provided by the framework-aware layers to set `hasErrorBoundary`
643
673
  * from the framework-aware `errorElement` prop
644
674
  *
645
675
  * @deprecated Use `mapRouteProperties` instead
646
676
  */
677
+
647
678
  /**
648
679
  * Result from a loader or action called via dataStrategy
649
680
  */
681
+
650
682
  /**
651
683
  * Function provided by the framework-aware layers to set any framework-specific
652
684
  * properties from framework-agnostic properties
653
685
  */
686
+
654
687
  /**
655
688
  * Keys we cannot change from within a lazy() function. We spread all other keys
656
689
  * onto the route. Either they're meaningful to the router, or they'll get
657
690
  * ignored.
658
691
  */
692
+
659
693
  const immutableRouteKeys = new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
660
694
 
661
695
  /**
@@ -699,12 +733,15 @@
699
733
  // Attempt to parse the given string segment. If it fails, then just return the
700
734
  // plain string type as a default fallback. Otherwise, return the union of the
701
735
  // parsed string literals that were referenced as dynamic segments in the route.
736
+
702
737
  /**
703
738
  * The parameters that were parsed from the URL path.
704
739
  */
740
+
705
741
  /**
706
742
  * A RouteMatch contains info about how a route matched a URL.
707
743
  */
744
+
708
745
  function isIndexRoute(route) {
709
746
  return route.index === true;
710
747
  }
@@ -763,6 +800,7 @@
763
800
  let branches = flattenRoutes(routes);
764
801
  rankRouteBranches(branches);
765
802
  let matches = null;
803
+ let decoded = decodePath(pathname);
766
804
  for (let i = 0; matches == null && i < branches.length; ++i) {
767
805
  // Incoming pathnames are generally encoded from either window.location
768
806
  // or from router.navigate, but we want to match against the unencoded
@@ -770,7 +808,6 @@
770
808
  // encoded here but there also shouldn't be anything to decode so this
771
809
  // should be a safe operation. This avoids needing matchRoutes to be
772
810
  // history-aware.
773
- let decoded = decodePath(pathname);
774
811
  matches = matchRouteBranch(branches[i], decoded, allowPartial);
775
812
  }
776
813
  return matches;
@@ -1142,8 +1179,6 @@
1142
1179
  }
1143
1180
  return pathname.slice(startIndex) || "/";
1144
1181
  }
1145
- const ABSOLUTE_URL_REGEX$1 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1146
- const isAbsoluteUrl = url => ABSOLUTE_URL_REGEX$1.test(url);
1147
1182
 
1148
1183
  /**
1149
1184
  * Returns a resolved path object relative to the given pathname.
@@ -1161,19 +1196,11 @@
1161
1196
  } = typeof to === "string" ? parsePath(to) : to;
1162
1197
  let pathname;
1163
1198
  if (toPathname) {
1164
- if (isAbsoluteUrl(toPathname)) {
1165
- pathname = toPathname;
1199
+ toPathname = removeDoubleSlashes(toPathname);
1200
+ if (toPathname.startsWith("/")) {
1201
+ pathname = resolvePathname(toPathname.substring(1), "/");
1166
1202
  } else {
1167
- if (toPathname.includes("//")) {
1168
- let oldPathname = toPathname;
1169
- toPathname = toPathname.replace(/\/\/+/g, "/");
1170
- warning(false, "Pathnames cannot have embedded double slashes - normalizing " + (oldPathname + " -> " + toPathname));
1171
- }
1172
- if (toPathname.startsWith("/")) {
1173
- pathname = resolvePathname(toPathname.substring(1), "/");
1174
- } else {
1175
- pathname = resolvePathname(toPathname, fromPathname);
1176
- }
1203
+ pathname = resolvePathname(toPathname, fromPathname);
1177
1204
  }
1178
1205
  } else {
1179
1206
  pathname = fromPathname;
@@ -1309,11 +1336,12 @@
1309
1336
  // Empty strings should be treated the same as / paths
1310
1337
  return to === "" || to.pathname === "" ? "/" : typeof to === "string" ? parsePath(to).pathname : to.pathname;
1311
1338
  }
1339
+ const removeDoubleSlashes = path => path.replace(/\/\/+/g, "/");
1312
1340
 
1313
1341
  /**
1314
1342
  * @private
1315
1343
  */
1316
- const joinPaths = paths => paths.join("/").replace(/\/\/+/g, "/");
1344
+ const joinPaths = paths => removeDoubleSlashes(paths.join("/"));
1317
1345
 
1318
1346
  /**
1319
1347
  * @private
@@ -1606,69 +1634,92 @@
1606
1634
  /**
1607
1635
  * A Router instance manages all navigation and data loading/mutations
1608
1636
  */
1637
+
1609
1638
  /**
1610
1639
  * State maintained internally by the router. During a navigation, all states
1611
1640
  * reflect the the "old" location unless otherwise noted.
1612
1641
  */
1642
+
1613
1643
  /**
1614
1644
  * Data that can be passed into hydrate a Router from SSR
1615
1645
  */
1646
+
1616
1647
  /**
1617
1648
  * Future flags to toggle new feature behavior
1618
1649
  */
1650
+
1619
1651
  /**
1620
1652
  * Initialization options for createRouter
1621
1653
  */
1654
+
1622
1655
  /**
1623
1656
  * State returned from a server-side query() call
1624
1657
  */
1658
+
1625
1659
  /**
1626
1660
  * A StaticHandler instance manages a singular SSR navigation/fetch event
1627
1661
  */
1662
+
1628
1663
  /**
1629
1664
  * Subscriber function signature for changes to router state
1630
1665
  */
1666
+
1631
1667
  /**
1632
1668
  * Function signature for determining the key to be used in scroll restoration
1633
1669
  * for a given location
1634
1670
  */
1671
+
1635
1672
  /**
1636
1673
  * Function signature for determining the current scroll position
1637
1674
  */
1675
+
1638
1676
  // Allowed for any navigation or fetch
1677
+
1639
1678
  // Only allowed for navigations
1679
+
1640
1680
  // Only allowed for submission navigations
1681
+
1641
1682
  /**
1642
1683
  * Options for a navigate() call for a normal (non-submission) navigation
1643
1684
  */
1685
+
1644
1686
  /**
1645
1687
  * Options for a navigate() call for a submission navigation
1646
1688
  */
1689
+
1647
1690
  /**
1648
1691
  * Options to pass to navigate() for a navigation
1649
1692
  */
1693
+
1650
1694
  /**
1651
1695
  * Options for a fetch() load
1652
1696
  */
1697
+
1653
1698
  /**
1654
1699
  * Options for a fetch() submission
1655
1700
  */
1701
+
1656
1702
  /**
1657
1703
  * Options to pass to fetch()
1658
1704
  */
1705
+
1659
1706
  /**
1660
1707
  * Potential states for state.navigation
1661
1708
  */
1709
+
1662
1710
  /**
1663
1711
  * Potential states for fetchers
1664
1712
  */
1713
+
1665
1714
  /**
1666
1715
  * Cached info for active fetcher.load() instances so they can participate
1667
1716
  * in revalidation
1668
1717
  */
1718
+
1669
1719
  /**
1670
1720
  * Identified fetcher.load() calls that need to be revalidated
1671
1721
  */
1722
+
1672
1723
  const validMutationMethodsArr = ["post", "put", "patch", "delete"];
1673
1724
  const validMutationMethods = new Set(validMutationMethodsArr);
1674
1725
  const validRequestMethodsArr = ["get", ...validMutationMethodsArr];
@@ -4971,7 +5022,7 @@
4971
5022
  }
4972
5023
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4973
5024
  if (url.origin === currentUrl.origin && isSameBasename) {
4974
- return url.pathname + url.search + url.hash;
5025
+ return removeDoubleSlashes(url.pathname) + url.search + url.hash;
4975
5026
  }
4976
5027
  }
4977
5028
  try {