react-router 5.2.0 → 5.3.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.
@@ -6,10 +6,19 @@
6
6
 
7
7
  var React__default = 'default' in React ? React['default'] : React;
8
8
 
9
+ function _setPrototypeOf(o, p) {
10
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
11
+ o.__proto__ = p;
12
+ return o;
13
+ };
14
+
15
+ return _setPrototypeOf(o, p);
16
+ }
17
+
9
18
  function _inheritsLoose(subClass, superClass) {
10
19
  subClass.prototype = Object.create(superClass.prototype);
11
20
  subClass.prototype.constructor = subClass;
12
- subClass.__proto__ = superClass;
21
+ _setPrototypeOf(subClass, superClass);
13
22
  }
14
23
 
15
24
  function unwrapExports (x) {
@@ -1571,12 +1580,6 @@
1571
1580
  return history;
1572
1581
  }
1573
1582
 
1574
- function _inheritsLoose$1(subClass, superClass) {
1575
- subClass.prototype = Object.create(superClass.prototype);
1576
- subClass.prototype.constructor = subClass;
1577
- subClass.__proto__ = superClass;
1578
- }
1579
-
1580
1583
  var MAX_SIGNED_31_BIT_INT = 1073741823;
1581
1584
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {};
1582
1585
 
@@ -1626,7 +1629,7 @@
1626
1629
  var contextProp = '__create-react-context-' + getUniqueId() + '__';
1627
1630
 
1628
1631
  var Provider = /*#__PURE__*/function (_Component) {
1629
- _inheritsLoose$1(Provider, _Component);
1632
+ _inheritsLoose(Provider, _Component);
1630
1633
 
1631
1634
  function Provider() {
1632
1635
  var _this;
@@ -1678,7 +1681,7 @@
1678
1681
  Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = propTypes.object.isRequired, _Provider$childContex);
1679
1682
 
1680
1683
  var Consumer = /*#__PURE__*/function (_Component2) {
1681
- _inheritsLoose$1(Consumer, _Component2);
1684
+ _inheritsLoose(Consumer, _Component2);
1682
1685
 
1683
1686
  function Consumer() {
1684
1687
  var _this2;
@@ -1755,29 +1758,15 @@
1755
1758
  return context;
1756
1759
  };
1757
1760
 
1758
- var historyContext =
1759
- /*#__PURE__*/
1760
- createNamedContext("Router-History");
1761
-
1762
- // TODO: Replace with React.createContext once we can assume React 16+
1763
-
1764
- var createNamedContext$1 = function createNamedContext(name) {
1765
- var context = index();
1766
- context.displayName = name;
1767
- return context;
1768
- };
1761
+ var historyContext = /*#__PURE__*/createNamedContext("Router-History");
1769
1762
 
1770
- var context =
1771
- /*#__PURE__*/
1772
- createNamedContext$1("Router");
1763
+ var context = /*#__PURE__*/createNamedContext("Router");
1773
1764
 
1774
1765
  /**
1775
1766
  * The public API for putting history on context.
1776
1767
  */
1777
1768
 
1778
- var Router =
1779
- /*#__PURE__*/
1780
- function (_React$Component) {
1769
+ var Router = /*#__PURE__*/function (_React$Component) {
1781
1770
  _inheritsLoose(Router, _React$Component);
1782
1771
 
1783
1772
  Router.computeRootMatch = function computeRootMatch(pathname) {
@@ -1806,13 +1795,7 @@
1806
1795
 
1807
1796
  if (!props.staticContext) {
1808
1797
  _this.unlisten = props.history.listen(function (location) {
1809
- if (_this._isMounted) {
1810
- _this.setState({
1811
- location: location
1812
- });
1813
- } else {
1814
- _this._pendingLocation = location;
1815
- }
1798
+ _this._pendingLocation = location;
1816
1799
  });
1817
1800
  }
1818
1801
 
@@ -1822,8 +1805,26 @@
1822
1805
  var _proto = Router.prototype;
1823
1806
 
1824
1807
  _proto.componentDidMount = function componentDidMount() {
1808
+ var _this2 = this;
1809
+
1825
1810
  this._isMounted = true;
1826
1811
 
1812
+ if (this.unlisten) {
1813
+ // Any pre-mount location changes have been captured at
1814
+ // this point, so unregister the listener.
1815
+ this.unlisten();
1816
+ }
1817
+
1818
+ if (!this.props.staticContext) {
1819
+ this.unlisten = this.props.history.listen(function (location) {
1820
+ if (_this2._isMounted) {
1821
+ _this2.setState({
1822
+ location: location
1823
+ });
1824
+ }
1825
+ });
1826
+ }
1827
+
1827
1828
  if (this._pendingLocation) {
1828
1829
  this.setState({
1829
1830
  location: this._pendingLocation
@@ -1832,18 +1833,22 @@
1832
1833
  };
1833
1834
 
1834
1835
  _proto.componentWillUnmount = function componentWillUnmount() {
1835
- if (this.unlisten) this.unlisten();
1836
+ if (this.unlisten) {
1837
+ this.unlisten();
1838
+ this._isMounted = false;
1839
+ this._pendingLocation = null;
1840
+ }
1836
1841
  };
1837
1842
 
1838
1843
  _proto.render = function render() {
1839
- return React__default.createElement(context.Provider, {
1844
+ return /*#__PURE__*/React__default.createElement(context.Provider, {
1840
1845
  value: {
1841
1846
  history: this.props.history,
1842
1847
  location: this.state.location,
1843
1848
  match: Router.computeRootMatch(this.state.location.pathname),
1844
1849
  staticContext: this.props.staticContext
1845
1850
  }
1846
- }, React__default.createElement(historyContext.Provider, {
1851
+ }, /*#__PURE__*/React__default.createElement(historyContext.Provider, {
1847
1852
  children: this.props.children || null,
1848
1853
  value: this.props.history
1849
1854
  }));
@@ -1868,9 +1873,7 @@
1868
1873
  * The public API for a <Router> that stores location in memory.
1869
1874
  */
1870
1875
 
1871
- var MemoryRouter =
1872
- /*#__PURE__*/
1873
- function (_React$Component) {
1876
+ var MemoryRouter = /*#__PURE__*/function (_React$Component) {
1874
1877
  _inheritsLoose(MemoryRouter, _React$Component);
1875
1878
 
1876
1879
  function MemoryRouter() {
@@ -1888,7 +1891,7 @@
1888
1891
  var _proto = MemoryRouter.prototype;
1889
1892
 
1890
1893
  _proto.render = function render() {
1891
- return React__default.createElement(Router, {
1894
+ return /*#__PURE__*/React__default.createElement(Router, {
1892
1895
  history: this.history,
1893
1896
  children: this.props.children
1894
1897
  });
@@ -1911,9 +1914,7 @@
1911
1914
  };
1912
1915
  }
1913
1916
 
1914
- var Lifecycle =
1915
- /*#__PURE__*/
1916
- function (_React$Component) {
1917
+ var Lifecycle = /*#__PURE__*/function (_React$Component) {
1917
1918
  _inheritsLoose(Lifecycle, _React$Component);
1918
1919
 
1919
1920
  function Lifecycle() {
@@ -1949,11 +1950,11 @@
1949
1950
  var message = _ref.message,
1950
1951
  _ref$when = _ref.when,
1951
1952
  when = _ref$when === void 0 ? true : _ref$when;
1952
- return React__default.createElement(context.Consumer, null, function (context) {
1953
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
1953
1954
  !context ? invariant(false, "You should not use <Prompt> outside a <Router>") : void 0;
1954
1955
  if (!when || context.staticContext) return null;
1955
1956
  var method = context.history.block;
1956
- return React__default.createElement(Lifecycle, {
1957
+ return /*#__PURE__*/React__default.createElement(Lifecycle, {
1957
1958
  onMount: function onMount(self) {
1958
1959
  self.release = method(message);
1959
1960
  },
@@ -2455,7 +2456,7 @@
2455
2456
  to = _ref.to,
2456
2457
  _ref$push = _ref.push,
2457
2458
  push = _ref$push === void 0 ? false : _ref$push;
2458
- return React__default.createElement(context.Consumer, null, function (context) {
2459
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
2459
2460
  !context ? invariant(false, "You should not use <Redirect> outside a <Router>") : void 0;
2460
2461
  var history = context.history,
2461
2462
  staticContext = context.staticContext;
@@ -2470,7 +2471,7 @@
2470
2471
  return null;
2471
2472
  }
2472
2473
 
2473
- return React__default.createElement(Lifecycle, {
2474
+ return /*#__PURE__*/React__default.createElement(Lifecycle, {
2474
2475
  onMount: function onMount() {
2475
2476
  method(location);
2476
2477
  },
@@ -2590,9 +2591,7 @@
2590
2591
  */
2591
2592
 
2592
2593
 
2593
- var Route =
2594
- /*#__PURE__*/
2595
- function (_React$Component) {
2594
+ var Route = /*#__PURE__*/function (_React$Component) {
2596
2595
  _inheritsLoose(Route, _React$Component);
2597
2596
 
2598
2597
  function Route() {
@@ -2604,7 +2603,7 @@
2604
2603
  _proto.render = function render() {
2605
2604
  var _this = this;
2606
2605
 
2607
- return React__default.createElement(context.Consumer, null, function (context$1) {
2606
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context$1) {
2608
2607
  !context$1 ? invariant(false, "You should not use <Route> outside a <Router>") : void 0;
2609
2608
  var location = _this.props.location || context$1.location;
2610
2609
  var match = _this.props.computedMatch ? _this.props.computedMatch // <Switch> already computed the match for us
@@ -2621,13 +2620,13 @@
2621
2620
  render = _this$props.render; // Preact uses an empty array as children by
2622
2621
  // default, so use null if that's the case.
2623
2622
 
2624
- if (Array.isArray(children) && children.length === 0) {
2623
+ if (Array.isArray(children) && isEmptyChildren(children)) {
2625
2624
  children = null;
2626
2625
  }
2627
2626
 
2628
- return React__default.createElement(context.Provider, {
2627
+ return /*#__PURE__*/React__default.createElement(context.Provider, {
2629
2628
  value: props
2630
- }, props.match ? children ? typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : children : component ? React__default.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : null);
2629
+ }, props.match ? children ? typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : children : component ? /*#__PURE__*/React__default.createElement(component, props) : render ? render(props) : null : typeof children === "function" ? evalChildrenDev(children, props, _this.props.path) : null);
2631
2630
  });
2632
2631
  };
2633
2632
 
@@ -2716,9 +2715,7 @@
2716
2715
  */
2717
2716
 
2718
2717
 
2719
- var StaticRouter =
2720
- /*#__PURE__*/
2721
- function (_React$Component) {
2718
+ var StaticRouter = /*#__PURE__*/function (_React$Component) {
2722
2719
  _inheritsLoose(StaticRouter, _React$Component);
2723
2720
 
2724
2721
  function StaticRouter() {
@@ -2786,7 +2783,7 @@
2786
2783
  listen: this.handleListen,
2787
2784
  block: this.handleBlock
2788
2785
  };
2789
- return React__default.createElement(Router, _extends({}, rest, {
2786
+ return /*#__PURE__*/React__default.createElement(Router, _extends({}, rest, {
2790
2787
  history: history,
2791
2788
  staticContext: context
2792
2789
  }));
@@ -2811,9 +2808,7 @@
2811
2808
  * The public API for rendering the first <Route> that matches.
2812
2809
  */
2813
2810
 
2814
- var Switch =
2815
- /*#__PURE__*/
2816
- function (_React$Component) {
2811
+ var Switch = /*#__PURE__*/function (_React$Component) {
2817
2812
  _inheritsLoose(Switch, _React$Component);
2818
2813
 
2819
2814
  function Switch() {
@@ -2825,7 +2820,7 @@
2825
2820
  _proto.render = function render() {
2826
2821
  var _this = this;
2827
2822
 
2828
- return React__default.createElement(context.Consumer, null, function (context) {
2823
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
2829
2824
  !context ? invariant(false, "You should not use <Switch> outside a <Router>") : void 0;
2830
2825
  var location = _this.props.location || context.location;
2831
2826
  var element, match; // We use React.Children.forEach instead of React.Children.toArray().find()
@@ -2834,7 +2829,7 @@
2834
2829
  // component at different URLs.
2835
2830
 
2836
2831
  React__default.Children.forEach(_this.props.children, function (child) {
2837
- if (match == null && React__default.isValidElement(child)) {
2832
+ if (match == null && /*#__PURE__*/React__default.isValidElement(child)) {
2838
2833
  element = child;
2839
2834
  var path = child.props.path || child.props.from;
2840
2835
  match = path ? matchPath(location.pathname, _extends({}, child.props, {
@@ -2842,7 +2837,7 @@
2842
2837
  })) : context.match;
2843
2838
  }
2844
2839
  });
2845
- return match ? React__default.cloneElement(element, {
2840
+ return match ? /*#__PURE__*/React__default.cloneElement(element, {
2846
2841
  location: location,
2847
2842
  computedMatch: match
2848
2843
  }) : null;
@@ -2977,9 +2972,9 @@
2977
2972
  var wrappedComponentRef = props.wrappedComponentRef,
2978
2973
  remainingProps = _objectWithoutPropertiesLoose(props, ["wrappedComponentRef"]);
2979
2974
 
2980
- return React__default.createElement(context.Consumer, null, function (context) {
2975
+ return /*#__PURE__*/React__default.createElement(context.Consumer, null, function (context) {
2981
2976
  !context ? invariant(false, "You should not use <" + displayName + " /> outside a <Router>") : void 0;
2982
- return React__default.createElement(Component, _extends({}, remainingProps, context, {
2977
+ return /*#__PURE__*/React__default.createElement(Component, _extends({}, remainingProps, context, {
2983
2978
  ref: wrappedComponentRef
2984
2979
  }));
2985
2980
  });