@remix-run/router 1.23.2 → 1.23.3

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.3
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;
@@ -1166,7 +1203,7 @@
1166
1203
  } else {
1167
1204
  if (toPathname.includes("//")) {
1168
1205
  let oldPathname = toPathname;
1169
- toPathname = toPathname.replace(/\/\/+/g, "/");
1206
+ toPathname = removeDoubleSlashes(toPathname);
1170
1207
  warning(false, "Pathnames cannot have embedded double slashes - normalizing " + (oldPathname + " -> " + toPathname));
1171
1208
  }
1172
1209
  if (toPathname.startsWith("/")) {
@@ -1309,11 +1346,12 @@
1309
1346
  // Empty strings should be treated the same as / paths
1310
1347
  return to === "" || to.pathname === "" ? "/" : typeof to === "string" ? parsePath(to).pathname : to.pathname;
1311
1348
  }
1349
+ const removeDoubleSlashes = path => path.replace(/\/\/+/g, "/");
1312
1350
 
1313
1351
  /**
1314
1352
  * @private
1315
1353
  */
1316
- const joinPaths = paths => paths.join("/").replace(/\/\/+/g, "/");
1354
+ const joinPaths = paths => removeDoubleSlashes(paths.join("/"));
1317
1355
 
1318
1356
  /**
1319
1357
  * @private
@@ -1606,69 +1644,92 @@
1606
1644
  /**
1607
1645
  * A Router instance manages all navigation and data loading/mutations
1608
1646
  */
1647
+
1609
1648
  /**
1610
1649
  * State maintained internally by the router. During a navigation, all states
1611
1650
  * reflect the the "old" location unless otherwise noted.
1612
1651
  */
1652
+
1613
1653
  /**
1614
1654
  * Data that can be passed into hydrate a Router from SSR
1615
1655
  */
1656
+
1616
1657
  /**
1617
1658
  * Future flags to toggle new feature behavior
1618
1659
  */
1660
+
1619
1661
  /**
1620
1662
  * Initialization options for createRouter
1621
1663
  */
1664
+
1622
1665
  /**
1623
1666
  * State returned from a server-side query() call
1624
1667
  */
1668
+
1625
1669
  /**
1626
1670
  * A StaticHandler instance manages a singular SSR navigation/fetch event
1627
1671
  */
1672
+
1628
1673
  /**
1629
1674
  * Subscriber function signature for changes to router state
1630
1675
  */
1676
+
1631
1677
  /**
1632
1678
  * Function signature for determining the key to be used in scroll restoration
1633
1679
  * for a given location
1634
1680
  */
1681
+
1635
1682
  /**
1636
1683
  * Function signature for determining the current scroll position
1637
1684
  */
1685
+
1638
1686
  // Allowed for any navigation or fetch
1687
+
1639
1688
  // Only allowed for navigations
1689
+
1640
1690
  // Only allowed for submission navigations
1691
+
1641
1692
  /**
1642
1693
  * Options for a navigate() call for a normal (non-submission) navigation
1643
1694
  */
1695
+
1644
1696
  /**
1645
1697
  * Options for a navigate() call for a submission navigation
1646
1698
  */
1699
+
1647
1700
  /**
1648
1701
  * Options to pass to navigate() for a navigation
1649
1702
  */
1703
+
1650
1704
  /**
1651
1705
  * Options for a fetch() load
1652
1706
  */
1707
+
1653
1708
  /**
1654
1709
  * Options for a fetch() submission
1655
1710
  */
1711
+
1656
1712
  /**
1657
1713
  * Options to pass to fetch()
1658
1714
  */
1715
+
1659
1716
  /**
1660
1717
  * Potential states for state.navigation
1661
1718
  */
1719
+
1662
1720
  /**
1663
1721
  * Potential states for fetchers
1664
1722
  */
1723
+
1665
1724
  /**
1666
1725
  * Cached info for active fetcher.load() instances so they can participate
1667
1726
  * in revalidation
1668
1727
  */
1728
+
1669
1729
  /**
1670
1730
  * Identified fetcher.load() calls that need to be revalidated
1671
1731
  */
1732
+
1672
1733
  const validMutationMethodsArr = ["post", "put", "patch", "delete"];
1673
1734
  const validMutationMethods = new Set(validMutationMethodsArr);
1674
1735
  const validRequestMethodsArr = ["get", ...validMutationMethodsArr];
@@ -4971,7 +5032,7 @@
4971
5032
  }
4972
5033
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4973
5034
  if (url.origin === currentUrl.origin && isSameBasename) {
4974
- return url.pathname + url.search + url.hash;
5035
+ return removeDoubleSlashes(url.pathname) + url.search + url.hash;
4975
5036
  }
4976
5037
  }
4977
5038
  try {