react-router 4.4.0-beta.6 → 5.0.1

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/README.md CHANGED
@@ -10,17 +10,16 @@ Using [npm](https://www.npmjs.com/):
10
10
 
11
11
  **Note:** This package provides the core routing functionality for React Router, but you might not want to install it directly. If you are writing an application that will run in the browser, you should instead install `react-router-dom`. Similarly, if you are writing a React Native application, you should instead install `react-router-native`. Both of those will install `react-router` as a dependency.
12
12
 
13
-
14
13
  Then with a module bundler like [webpack](https://webpack.github.io/), use as you would anything else:
15
14
 
16
15
  ```js
17
16
  // using ES6 modules
18
- import { Router, Route, Switch } from 'react-router'
17
+ import { Router, Route, Switch } from "react-router";
19
18
 
20
19
  // using CommonJS modules
21
- var Router = require('react-router').Router
22
- var Route = require('react-router').Route
23
- var Switch = require('react-router').Switch
20
+ var Router = require("react-router").Router;
21
+ var Route = require("react-router").Route;
22
+ var Switch = require("react-router").Switch;
24
23
  ```
25
24
 
26
25
  The UMD build is also available on [unpkg](https://unpkg.com):
@@ -1,13 +1,11 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
4
 
7
- var createContext = _interopDefault(require('create-react-context'));
8
- var warning = _interopDefault(require('tiny-warning'));
5
+ var createContext = _interopDefault(require('mini-create-react-context'));
9
6
  var React = _interopDefault(require('react'));
10
7
  var PropTypes = _interopDefault(require('prop-types'));
8
+ var warning = _interopDefault(require('tiny-warning'));
11
9
  var history = require('history');
12
10
  var invariant = _interopDefault(require('tiny-invariant'));
13
11
  var pathToRegexp = _interopDefault(require('path-to-regexp'));
@@ -54,45 +52,21 @@ function _objectWithoutPropertiesLoose(source, excluded) {
54
52
  }
55
53
 
56
54
  // TODO: Replace with React.createContext once we can assume React 16+
57
- var context = createContext();
58
- context.Provider.displayName = "Router.Provider";
59
- context.Consumer.displayName = "Router.Consumer";
60
55
 
61
- var warnAboutGettingProperty = function warnAboutGettingProperty() {};
62
-
63
- {
64
- warnAboutGettingProperty = function warnAboutGettingProperty(object, key, message) {
65
- var didIssueWarning = false;
66
- var value = object[key];
67
- Object.defineProperty(object, key, {
68
- get: function get() {
69
- if (!didIssueWarning) {
70
- warning(false, message);
71
- didIssueWarning = true;
72
- }
73
-
74
- return value;
75
- },
76
- configurable: true
77
- });
78
- };
79
- }
56
+ var createNamedContext = function createNamedContext(name) {
57
+ var context = createContext();
58
+ context.displayName = name;
59
+ return context;
60
+ };
80
61
 
81
- var warnAboutGettingProperty$1 = warnAboutGettingProperty;
62
+ var context =
63
+ /*#__PURE__*/
64
+ createNamedContext("Router");
82
65
 
83
- function getContext(props, state) {
84
- return {
85
- history: props.history,
86
- location: state.location,
87
- match: Router.computeRootMatch(state.location.pathname),
88
- staticContext: props.staticContext
89
- };
90
- }
91
66
  /**
92
67
  * The public API for putting history on context.
93
68
  */
94
69
 
95
-
96
70
  var Router =
97
71
  /*#__PURE__*/
98
72
  function (_React$Component) {
@@ -154,39 +128,19 @@ function (_React$Component) {
154
128
  };
155
129
 
156
130
  _proto.render = function render() {
157
- var context$$1 = getContext(this.props, this.state);
158
131
  return React.createElement(context.Provider, {
159
132
  children: this.props.children || null,
160
- value: context$$1
133
+ value: {
134
+ history: this.props.history,
135
+ location: this.state.location,
136
+ match: Router.computeRootMatch(this.state.location.pathname),
137
+ staticContext: this.props.staticContext
138
+ }
161
139
  });
162
140
  };
163
141
 
164
142
  return Router;
165
- }(React.Component); // TODO: Remove this in v5
166
-
167
-
168
- if (!React.createContext) {
169
- Router.childContextTypes = {
170
- router: PropTypes.object.isRequired
171
- };
172
-
173
- Router.prototype.getChildContext = function () {
174
- var context$$1 = getContext(this.props, this.state);
175
-
176
- {
177
- var contextWithoutWarnings = _extends({}, context$$1);
178
-
179
- Object.keys(context$$1).forEach(function (key) {
180
- warnAboutGettingProperty$1(context$$1, key, "You should not be using this.context.router." + key + " directly. It is private API " + "for internal use only and is subject to change at any time. Instead, use " + "a <Route> or withRouter() to access the current location, match, etc.");
181
- });
182
- context$$1._withoutWarnings = contextWithoutWarnings;
183
- }
184
-
185
- return {
186
- router: context$$1
187
- };
188
- };
189
- }
143
+ }(React.Component);
190
144
 
191
145
  {
192
146
  Router.propTypes = {
@@ -281,12 +235,14 @@ function (_React$Component) {
281
235
  * The public API for prompting the user before navigating away from a screen.
282
236
  */
283
237
 
284
- function Prompt(props) {
238
+ function Prompt(_ref) {
239
+ var message = _ref.message,
240
+ _ref$when = _ref.when,
241
+ when = _ref$when === void 0 ? true : _ref$when;
285
242
  return React.createElement(context.Consumer, null, function (context$$1) {
286
243
  !context$$1 ? invariant(false, "You should not use <Prompt> outside a <Router>") : void 0;
287
- if (!props.when || context$$1.staticContext) return null;
244
+ if (!when || context$$1.staticContext) return null;
288
245
  var method = context$$1.history.block;
289
- var message = props.message;
290
246
  return React.createElement(Lifecycle, {
291
247
  onMount: function onMount(self) {
292
248
  self.release = method(message);
@@ -299,15 +255,12 @@ function Prompt(props) {
299
255
  },
300
256
  onUnmount: function onUnmount(self) {
301
257
  self.release();
302
- }
258
+ },
259
+ message: message
303
260
  });
304
261
  });
305
262
  }
306
263
 
307
- Prompt.defaultProps = {
308
- when: true
309
- };
310
-
311
264
  {
312
265
  var messageType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]);
313
266
  Prompt.propTypes = {
@@ -354,27 +307,37 @@ function generatePath(path, params) {
354
307
  * The public API for navigating programmatically with a component.
355
308
  */
356
309
 
357
- function Redirect(props) {
310
+ function Redirect(_ref) {
311
+ var computedMatch = _ref.computedMatch,
312
+ to = _ref.to,
313
+ _ref$push = _ref.push,
314
+ push = _ref$push === void 0 ? false : _ref$push;
358
315
  return React.createElement(context.Consumer, null, function (context$$1) {
359
316
  !context$$1 ? invariant(false, "You should not use <Redirect> outside a <Router>") : void 0;
360
- var method = props.push ? context$$1.history.push : context$$1.history.replace;
361
- var to = history.createLocation(props.computedMatch ? typeof props.to === "string" ? generatePath(props.to, props.computedMatch.params) : _extends({}, props.to, {
362
- pathname: generatePath(props.to.pathname, props.computedMatch.params)
363
- }) : props.to); // When rendering in a static context,
317
+ var history$$1 = context$$1.history,
318
+ staticContext = context$$1.staticContext;
319
+ var method = push ? history$$1.push : history$$1.replace;
320
+ var location = history.createLocation(computedMatch ? typeof to === "string" ? generatePath(to, computedMatch.params) : _extends({}, to, {
321
+ pathname: generatePath(to.pathname, computedMatch.params)
322
+ }) : to); // When rendering in a static context,
364
323
  // set the new location immediately.
365
324
 
366
- if (context$$1.staticContext) {
367
- method(to);
325
+ if (staticContext) {
326
+ method(location);
368
327
  return null;
369
328
  }
370
329
 
371
330
  return React.createElement(Lifecycle, {
372
331
  onMount: function onMount() {
373
- method(to);
332
+ method(location);
374
333
  },
375
334
  onUpdate: function onUpdate(self, prevProps) {
376
- if (!history.locationsAreEqual(prevProps.to, to)) {
377
- method(to);
335
+ var prevLocation = history.createLocation(prevProps.to);
336
+
337
+ if (!history.locationsAreEqual(prevLocation, _extends({}, location, {
338
+ key: prevLocation.key
339
+ }))) {
340
+ method(location);
378
341
  }
379
342
  },
380
343
  to: to
@@ -382,10 +345,6 @@ function Redirect(props) {
382
345
  });
383
346
  }
384
347
 
385
- Redirect.defaultProps = {
386
- push: false
387
- };
388
-
389
348
  {
390
349
  Redirect.propTypes = {
391
350
  push: PropTypes.bool,
@@ -439,6 +398,7 @@ function matchPath(pathname, options) {
439
398
  sensitive = _options$sensitive === void 0 ? false : _options$sensitive;
440
399
  var paths = [].concat(path);
441
400
  return paths.reduce(function (matched, path) {
401
+ if (!path) return null;
442
402
  if (matched) return matched;
443
403
 
444
404
  var _compilePath = compilePath$1(path, {
@@ -473,16 +433,6 @@ function matchPath(pathname, options) {
473
433
  function isEmptyChildren(children) {
474
434
  return React.Children.count(children) === 0;
475
435
  }
476
-
477
- function getContext$1(props, context$$1) {
478
- var location = props.location || context$$1.location;
479
- var match = props.computedMatch ? props.computedMatch // <Switch> already computed the match for us
480
- : props.path ? matchPath(location.pathname, props) : context$$1.match;
481
- return _extends({}, context$$1, {
482
- location: location,
483
- match: match
484
- });
485
- }
486
436
  /**
487
437
  * The public API for matching a single path and rendering.
488
438
  */
@@ -504,7 +454,15 @@ function (_React$Component) {
504
454
 
505
455
  return React.createElement(context.Consumer, null, function (context$$1) {
506
456
  !context$$1 ? invariant(false, "You should not use <Route> outside a <Router>") : void 0;
507
- var props = getContext$1(_this.props, context$$1);
457
+ var location = _this.props.location || context$$1.location;
458
+ var match = _this.props.computedMatch ? _this.props.computedMatch // <Switch> already computed the match for us
459
+ : _this.props.path ? matchPath(location.pathname, _this.props) : context$$1.match;
460
+
461
+ var props = _extends({}, context$$1, {
462
+ location: location,
463
+ match: match
464
+ });
465
+
508
466
  var _this$props = _this.props,
509
467
  children = _this$props.children,
510
468
  component = _this$props.component,
@@ -535,41 +493,7 @@ function (_React$Component) {
535
493
  };
536
494
 
537
495
  return Route;
538
- }(React.Component); // TODO: Remove this in v5
539
-
540
-
541
- if (!React.createContext) {
542
- Route.contextTypes = {
543
- router: PropTypes.object.isRequired
544
- };
545
- Route.childContextTypes = {
546
- router: PropTypes.object.isRequired
547
- };
548
-
549
- Route.prototype.getChildContext = function () {
550
- !this.context.router ? invariant(false, "You should not use <Route> outside a <Router>") : void 0;
551
- var parentContext = this.context.router;
552
-
553
- {
554
- parentContext = parentContext._withoutWarnings;
555
- }
556
-
557
- var context$$1 = getContext$1(this.props, parentContext);
558
-
559
- {
560
- var contextWithoutWarnings = _extends({}, context$$1);
561
-
562
- Object.keys(context$$1).forEach(function (key) {
563
- warnAboutGettingProperty$1(context$$1, key, "You should not be using this.context.router." + key + " directly. It is private API " + "for internal use only and is subject to change at any time. Instead, use " + "a <Route> or withRouter() to access the current location, match, etc.");
564
- });
565
- context$$1._withoutWarnings = contextWithoutWarnings;
566
- }
567
-
568
- return {
569
- router: context$$1
570
- };
571
- };
572
- }
496
+ }(React.Component);
573
497
 
574
498
  {
575
499
  Route.propTypes = {
@@ -652,26 +576,12 @@ function (_React$Component) {
652
576
 
653
577
  _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
654
578
 
655
- _this.createHref = function (path) {
656
- return addLeadingSlash(_this.props.basename + createURL(path));
657
- };
658
-
659
579
  _this.handlePush = function (location) {
660
- var _this$props = _this.props,
661
- basename = _this$props.basename,
662
- context = _this$props.context;
663
- context.action = "PUSH";
664
- context.location = addBasename(basename, history.createLocation(location));
665
- context.url = createURL(context.location);
580
+ return _this.navigateTo(location, "PUSH");
666
581
  };
667
582
 
668
583
  _this.handleReplace = function (location) {
669
- var _this$props2 = _this.props,
670
- basename = _this$props2.basename,
671
- context = _this$props2.context;
672
- context.action = "REPLACE";
673
- context.location = addBasename(basename, history.createLocation(location));
674
- context.url = createURL(context.location);
584
+ return _this.navigateTo(location, "REPLACE");
675
585
  };
676
586
 
677
587
  _this.handleListen = function () {
@@ -687,15 +597,31 @@ function (_React$Component) {
687
597
 
688
598
  var _proto = StaticRouter.prototype;
689
599
 
600
+ _proto.navigateTo = function navigateTo(location, action) {
601
+ var _this$props = this.props,
602
+ _this$props$basename = _this$props.basename,
603
+ basename = _this$props$basename === void 0 ? "" : _this$props$basename,
604
+ _this$props$context = _this$props.context,
605
+ context = _this$props$context === void 0 ? {} : _this$props$context;
606
+ context.action = action;
607
+ context.location = addBasename(basename, history.createLocation(location));
608
+ context.url = createURL(context.location);
609
+ };
610
+
690
611
  _proto.render = function render() {
691
- var _this$props3 = this.props,
692
- basename = _this$props3.basename,
693
- context = _this$props3.context,
694
- location = _this$props3.location,
695
- rest = _objectWithoutPropertiesLoose(_this$props3, ["basename", "context", "location"]);
612
+ var _this$props2 = this.props,
613
+ _this$props2$basename = _this$props2.basename,
614
+ basename = _this$props2$basename === void 0 ? "" : _this$props2$basename,
615
+ _this$props2$context = _this$props2.context,
616
+ context = _this$props2$context === void 0 ? {} : _this$props2$context,
617
+ _this$props2$location = _this$props2.location,
618
+ location = _this$props2$location === void 0 ? "/" : _this$props2$location,
619
+ rest = _objectWithoutPropertiesLoose(_this$props2, ["basename", "context", "location"]);
696
620
 
697
621
  var history$$1 = {
698
- createHref: this.createHref,
622
+ createHref: function createHref(path) {
623
+ return addLeadingSlash(basename + createURL(path));
624
+ },
699
625
  action: "POP",
700
626
  location: stripBasename(basename, history.createLocation(location)),
701
627
  push: this.handlePush,
@@ -708,18 +634,13 @@ function (_React$Component) {
708
634
  };
709
635
  return React.createElement(Router, _extends({}, rest, {
710
636
  history: history$$1,
711
- staticContext: this.props.context || {}
637
+ staticContext: context
712
638
  }));
713
639
  };
714
640
 
715
641
  return StaticRouter;
716
642
  }(React.Component);
717
643
 
718
- StaticRouter.defaultProps = {
719
- basename: "",
720
- location: "/"
721
- };
722
-
723
644
  {
724
645
  StaticRouter.propTypes = {
725
646
  basename: PropTypes.string,
@@ -794,31 +715,54 @@ function (_React$Component) {
794
715
  */
795
716
 
796
717
  function withRouter(Component) {
718
+ var displayName = "withRouter(" + (Component.displayName || Component.name) + ")";
719
+
797
720
  var C = function C(props) {
798
721
  var wrappedComponentRef = props.wrappedComponentRef,
799
722
  remainingProps = _objectWithoutPropertiesLoose(props, ["wrappedComponentRef"]);
800
723
 
801
- return React.createElement(Route, {
802
- children: function children(routeComponentProps) {
803
- return React.createElement(Component, _extends({}, remainingProps, routeComponentProps, {
804
- ref: wrappedComponentRef
805
- }));
806
- }
724
+ return React.createElement(context.Consumer, null, function (context$$1) {
725
+ !context$$1 ? invariant(false, "You should not use <" + displayName + " /> outside a <Router>") : void 0;
726
+ return React.createElement(Component, _extends({}, remainingProps, context$$1, {
727
+ ref: wrappedComponentRef
728
+ }));
807
729
  });
808
730
  };
809
731
 
810
- C.displayName = "withRouter(" + (Component.displayName || Component.name) + ")";
732
+ C.displayName = displayName;
811
733
  C.WrappedComponent = Component;
812
734
 
813
735
  {
814
736
  C.propTypes = {
815
- wrappedComponentRef: PropTypes.func
737
+ wrappedComponentRef: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object])
816
738
  };
817
739
  }
818
740
 
819
741
  return hoistStatics(C, Component);
820
742
  }
821
743
 
744
+ {
745
+ if (typeof window !== "undefined") {
746
+ var global = window;
747
+ var key = "__react_router_build__";
748
+ var buildNames = {
749
+ cjs: "CommonJS",
750
+ esm: "ES modules",
751
+ umd: "UMD"
752
+ };
753
+
754
+ if (global[key] && global[key] !== "cjs") {
755
+ var initialBuildName = buildNames[global[key]];
756
+ var secondaryBuildName = buildNames["cjs"]; // TODO: Add link to article that explains in detail how to avoid
757
+ // loading 2 different builds.
758
+
759
+ throw new Error("You are loading the " + secondaryBuildName + " build of React Router " + ("on a page that is already running the " + initialBuildName + " ") + "build, so things won't work right.");
760
+ }
761
+
762
+ global[key] = "cjs";
763
+ }
764
+ }
765
+
822
766
  exports.MemoryRouter = MemoryRouter;
823
767
  exports.Prompt = Prompt;
824
768
  exports.Redirect = Redirect;
@@ -1 +1 @@
1
- "use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var createContext=_interopDefault(require("create-react-context"));require("tiny-warning");var React=_interopDefault(require("react")),PropTypes=_interopDefault(require("prop-types")),history=require("history"),invariant=_interopDefault(require("tiny-invariant")),pathToRegexp=_interopDefault(require("path-to-regexp"));require("react-is");var hoistStatics=_interopDefault(require("hoist-non-react-statics"));function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(this,arguments)}function _inheritsLoose(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}function _objectWithoutPropertiesLoose(t,e){if(null==t)return{};var n,o,r={},a=Object.keys(t);for(o=0;o<a.length;o++)n=a[o],0<=e.indexOf(n)||(r[n]=t[n]);return r}var context=createContext();function getContext(t,e){return{history:t.history,location:e.location,match:Router.computeRootMatch(e.location.pathname),staticContext:t.staticContext}}context.Provider.displayName="Router.Provider",context.Consumer.displayName="Router.Consumer";var Router=function(n){function t(t){var e;return(e=n.call(this,t)||this).state={location:t.history.location},e._isMounted=!1,e._pendingLocation=null,t.staticContext||(e.unlisten=t.history.listen(function(t){e._isMounted?e.setState({location:t}):e._pendingLocation=t})),e}_inheritsLoose(t,n),t.computeRootMatch=function(t){return{path:"/",url:"/",params:{},isExact:"/"===t}};var e=t.prototype;return e.componentDidMount=function(){this._isMounted=!0,this._pendingLocation&&this.setState({location:this._pendingLocation})},e.componentWillUnmount=function(){this.unlisten&&this.unlisten()},e.render=function(){var t=getContext(this.props,this.state);return React.createElement(context.Provider,{children:this.props.children||null,value:t})},t}(React.Component);React.createContext||(Router.childContextTypes={router:PropTypes.object.isRequired},Router.prototype.getChildContext=function(){return{router:getContext(this.props,this.state)}});var MemoryRouter=function(r){function t(){for(var t,e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];return(t=r.call.apply(r,[this].concat(n))||this).history=history.createMemoryHistory(t.props),t}return _inheritsLoose(t,r),t.prototype.render=function(){return React.createElement(Router,{history:this.history,children:this.props.children})},t}(React.Component),Lifecycle=function(t){function e(){return t.apply(this,arguments)||this}_inheritsLoose(e,t);var n=e.prototype;return n.componentDidMount=function(){this.props.onMount&&this.props.onMount.call(this,this)},n.componentDidUpdate=function(t){this.props.onUpdate&&this.props.onUpdate.call(this,this,t)},n.componentWillUnmount=function(){this.props.onUnmount&&this.props.onUnmount.call(this,this)},n.render=function(){return null},e}(React.Component);function Prompt(e){return React.createElement(context.Consumer,null,function(t){if(t||invariant(!1),!e.when||t.staticContext)return null;var n=t.history.block,o=e.message;return React.createElement(Lifecycle,{onMount:function(t){t.release=n(o)},onUpdate:function(t,e){e.message!==o&&(t.release(),t.release=n(o))},onUnmount:function(t){t.release()}})})}Prompt.defaultProps={when:!0};var cache={},cacheLimit=1e4,cacheCount=0;function compilePath(t){if(cache[t])return cache[t];var e=pathToRegexp.compile(t);return cacheCount<cacheLimit&&(cache[t]=e,cacheCount++),e}function generatePath(t,e){return void 0===t&&(t="/"),void 0===e&&(e={}),"/"===t?t:compilePath(t)(e,{pretty:!0})}function Redirect(e){return React.createElement(context.Consumer,null,function(t){t||invariant(!1);var n=e.push?t.history.push:t.history.replace,o=history.createLocation(e.computedMatch?"string"==typeof e.to?generatePath(e.to,e.computedMatch.params):_extends({},e.to,{pathname:generatePath(e.to.pathname,e.computedMatch.params)}):e.to);return t.staticContext?(n(o),null):React.createElement(Lifecycle,{onMount:function(){n(o)},onUpdate:function(t,e){history.locationsAreEqual(e.to,o)||n(o)},to:o})})}Redirect.defaultProps={push:!1};var cache$1={},cacheLimit$1=1e4,cacheCount$1=0;function compilePath$1(t,e){var n=""+e.end+e.strict+e.sensitive,o=cache$1[n]||(cache$1[n]={});if(o[t])return o[t];var r=[],a={regexp:pathToRegexp(t,r,e),keys:r};return cacheCount$1<cacheLimit$1&&(o[t]=a,cacheCount$1++),a}function matchPath(s,t){void 0===t&&(t={}),"string"==typeof t&&(t={path:t});var e=t,n=e.path,o=e.exact,p=void 0!==o&&o,r=e.strict,h=void 0!==r&&r,a=e.sensitive,l=void 0!==a&&a;return[].concat(n).reduce(function(t,e){if(t)return t;var n=compilePath$1(e,{end:p,strict:h,sensitive:l}),o=n.regexp,r=n.keys,a=o.exec(s);if(!a)return null;var i=a[0],c=a.slice(1),u=s===i;return p&&!u?null:{path:e,url:"/"===e&&""===i?"/":i,isExact:u,params:r.reduce(function(t,e,n){return t[e.name]=c[n],t},{})}},null)}function isEmptyChildren(t){return 0===React.Children.count(t)}function getContext$1(t,e){var n=t.location||e.location;return _extends({},e,{location:n,match:t.computedMatch?t.computedMatch:t.path?matchPath(n.pathname,t):e.match})}var Route=function(t){function e(){return t.apply(this,arguments)||this}return _inheritsLoose(e,t),e.prototype.render=function(){var i=this;return React.createElement(context.Consumer,null,function(t){t||invariant(!1);var e=getContext$1(i.props,t),n=i.props,o=n.children,r=n.component,a=n.render;return Array.isArray(o)&&0===o.length&&(o=null),"function"==typeof o&&void 0===(o=o(e))&&(o=null),React.createElement(context.Provider,{value:e},o&&!isEmptyChildren(o)?o:e.match?r?React.createElement(r,e):a?a(e):null:null)})},e}(React.Component);function addLeadingSlash(t){return"/"===t.charAt(0)?t:"/"+t}function addBasename(t,e){return t?_extends({},e,{pathname:addLeadingSlash(t)+e.pathname}):e}function stripBasename(t,e){if(!t)return e;var n=addLeadingSlash(t);return 0!==e.pathname.indexOf(n)?e:_extends({},e,{pathname:e.pathname.substr(n.length)})}function createURL(t){return"string"==typeof t?t:history.createPath(t)}function staticHandler(t){return function(){invariant(!1)}}function noop(){}React.createContext||(Route.contextTypes={router:PropTypes.object.isRequired},Route.childContextTypes={router:PropTypes.object.isRequired},Route.prototype.getChildContext=function(){this.context.router||invariant(!1);var t=this.context.router;return{router:getContext$1(this.props,t)}});var StaticRouter=function(o){function t(){for(var r,t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return(r=o.call.apply(o,[this].concat(e))||this).createHref=function(t){return addLeadingSlash(r.props.basename+createURL(t))},r.handlePush=function(t){var e=r.props,n=e.basename,o=e.context;o.action="PUSH",o.location=addBasename(n,history.createLocation(t)),o.url=createURL(o.location)},r.handleReplace=function(t){var e=r.props,n=e.basename,o=e.context;o.action="REPLACE",o.location=addBasename(n,history.createLocation(t)),o.url=createURL(o.location)},r.handleListen=function(){return noop},r.handleBlock=function(){return noop},r}return _inheritsLoose(t,o),t.prototype.render=function(){var t=this.props,e=t.basename,n=(t.context,t.location),o=_objectWithoutPropertiesLoose(t,["basename","context","location"]),r={createHref:this.createHref,action:"POP",location:stripBasename(e,history.createLocation(n)),push:this.handlePush,replace:this.handleReplace,go:staticHandler("go"),goBack:staticHandler("goBack"),goForward:staticHandler("goForward"),listen:this.handleListen,block:this.handleBlock};return React.createElement(Router,_extends({},o,{history:r,staticContext:this.props.context||{}}))},t}(React.Component);StaticRouter.defaultProps={basename:"",location:"/"};var Switch=function(t){function e(){return t.apply(this,arguments)||this}return _inheritsLoose(e,t),e.prototype.render=function(){var t=this;return React.createElement(context.Consumer,null,function(n){n||invariant(!1);var o,r,a=t.props.location||n.location;return React.Children.forEach(t.props.children,function(t){if(null==r&&React.isValidElement(t)){var e=(o=t).props.path||t.props.from;r=e?matchPath(a.pathname,_extends({},t.props,{path:e})):n.match}}),r?React.cloneElement(o,{location:a,computedMatch:r}):null})},e}(React.Component);function withRouter(o){var t=function(t){var e=t.wrappedComponentRef,n=_objectWithoutPropertiesLoose(t,["wrappedComponentRef"]);return React.createElement(Route,{children:function(t){return React.createElement(o,_extends({},n,t,{ref:e}))}})};return t.displayName="withRouter("+(o.displayName||o.name)+")",t.WrappedComponent=o,hoistStatics(t,o)}exports.MemoryRouter=MemoryRouter,exports.Prompt=Prompt,exports.Redirect=Redirect,exports.Route=Route,exports.Router=Router,exports.StaticRouter=StaticRouter,exports.Switch=Switch,exports.generatePath=generatePath,exports.matchPath=matchPath,exports.withRouter=withRouter,exports.__RouterContext=context;
1
+ "use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var createContext=_interopDefault(require("mini-create-react-context")),React=_interopDefault(require("react"));require("prop-types"),require("tiny-warning");var history=require("history"),invariant=_interopDefault(require("tiny-invariant")),pathToRegexp=_interopDefault(require("path-to-regexp"));require("react-is");var hoistStatics=_interopDefault(require("hoist-non-react-statics"));function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(this,arguments)}function _inheritsLoose(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}function _objectWithoutPropertiesLoose(t,e){if(null==t)return{};var n,o,r={},a=Object.keys(t);for(o=0;o<a.length;o++)n=a[o],0<=e.indexOf(n)||(r[n]=t[n]);return r}var createNamedContext=function(t){var e=createContext();return e.displayName=t,e},context=createNamedContext("Router"),Router=function(n){function t(t){var e;return(e=n.call(this,t)||this).state={location:t.history.location},e._isMounted=!1,e._pendingLocation=null,t.staticContext||(e.unlisten=t.history.listen(function(t){e._isMounted?e.setState({location:t}):e._pendingLocation=t})),e}_inheritsLoose(t,n),t.computeRootMatch=function(t){return{path:"/",url:"/",params:{},isExact:"/"===t}};var e=t.prototype;return e.componentDidMount=function(){this._isMounted=!0,this._pendingLocation&&this.setState({location:this._pendingLocation})},e.componentWillUnmount=function(){this.unlisten&&this.unlisten()},e.render=function(){return React.createElement(context.Provider,{children:this.props.children||null,value:{history:this.props.history,location:this.state.location,match:t.computeRootMatch(this.state.location.pathname),staticContext:this.props.staticContext}})},t}(React.Component),MemoryRouter=function(r){function t(){for(var t,e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];return(t=r.call.apply(r,[this].concat(n))||this).history=history.createMemoryHistory(t.props),t}return _inheritsLoose(t,r),t.prototype.render=function(){return React.createElement(Router,{history:this.history,children:this.props.children})},t}(React.Component),Lifecycle=function(t){function e(){return t.apply(this,arguments)||this}_inheritsLoose(e,t);var n=e.prototype;return n.componentDidMount=function(){this.props.onMount&&this.props.onMount.call(this,this)},n.componentDidUpdate=function(t){this.props.onUpdate&&this.props.onUpdate.call(this,this,t)},n.componentWillUnmount=function(){this.props.onUnmount&&this.props.onUnmount.call(this,this)},n.render=function(){return null},e}(React.Component);function Prompt(t){var o=t.message,e=t.when,r=void 0===e||e;return React.createElement(context.Consumer,null,function(t){if(t||invariant(!1),!r||t.staticContext)return null;var n=t.history.block;return React.createElement(Lifecycle,{onMount:function(t){t.release=n(o)},onUpdate:function(t,e){e.message!==o&&(t.release(),t.release=n(o))},onUnmount:function(t){t.release()},message:o})})}var cache={},cacheLimit=1e4,cacheCount=0;function compilePath(t){if(cache[t])return cache[t];var e=pathToRegexp.compile(t);return cacheCount<cacheLimit&&(cache[t]=e,cacheCount++),e}function generatePath(t,e){return void 0===t&&(t="/"),void 0===e&&(e={}),"/"===t?t:compilePath(t)(e,{pretty:!0})}function Redirect(t){var a=t.computedMatch,i=t.to,e=t.push,c=void 0!==e&&e;return React.createElement(context.Consumer,null,function(t){t||invariant(!1);var e=t.history,n=t.staticContext,o=c?e.push:e.replace,r=history.createLocation(a?"string"==typeof i?generatePath(i,a.params):_extends({},i,{pathname:generatePath(i.pathname,a.params)}):i);return n?(o(r),null):React.createElement(Lifecycle,{onMount:function(){o(r)},onUpdate:function(t,e){var n=history.createLocation(e.to);history.locationsAreEqual(n,_extends({},r,{key:n.key}))||o(r)},to:i})})}var cache$1={},cacheLimit$1=1e4,cacheCount$1=0;function compilePath$1(t,e){var n=""+e.end+e.strict+e.sensitive,o=cache$1[n]||(cache$1[n]={});if(o[t])return o[t];var r=[],a={regexp:pathToRegexp(t,r,e),keys:r};return cacheCount$1<cacheLimit$1&&(o[t]=a,cacheCount$1++),a}function matchPath(s,t){void 0===t&&(t={}),"string"==typeof t&&(t={path:t});var e=t,n=e.path,o=e.exact,p=void 0!==o&&o,r=e.strict,h=void 0!==r&&r,a=e.sensitive,l=void 0!==a&&a;return[].concat(n).reduce(function(t,e){if(!e)return null;if(t)return t;var n=compilePath$1(e,{end:p,strict:h,sensitive:l}),o=n.regexp,r=n.keys,a=o.exec(s);if(!a)return null;var i=a[0],c=a.slice(1),u=s===i;return p&&!u?null:{path:e,url:"/"===e&&""===i?"/":i,isExact:u,params:r.reduce(function(t,e,n){return t[e.name]=c[n],t},{})}},null)}function isEmptyChildren(t){return 0===React.Children.count(t)}var Route=function(t){function e(){return t.apply(this,arguments)||this}return _inheritsLoose(e,t),e.prototype.render=function(){var c=this;return React.createElement(context.Consumer,null,function(t){t||invariant(!1);var e=c.props.location||t.location,n=_extends({},t,{location:e,match:c.props.computedMatch?c.props.computedMatch:c.props.path?matchPath(e.pathname,c.props):t.match}),o=c.props,r=o.children,a=o.component,i=o.render;return Array.isArray(r)&&0===r.length&&(r=null),"function"==typeof r&&void 0===(r=r(n))&&(r=null),React.createElement(context.Provider,{value:n},r&&!isEmptyChildren(r)?r:n.match?a?React.createElement(a,n):i?i(n):null:null)})},e}(React.Component);function addLeadingSlash(t){return"/"===t.charAt(0)?t:"/"+t}function addBasename(t,e){return t?_extends({},e,{pathname:addLeadingSlash(t)+e.pathname}):e}function stripBasename(t,e){if(!t)return e;var n=addLeadingSlash(t);return 0!==e.pathname.indexOf(n)?e:_extends({},e,{pathname:e.pathname.substr(n.length)})}function createURL(t){return"string"==typeof t?t:history.createPath(t)}function staticHandler(t){return function(){invariant(!1)}}function noop(){}var StaticRouter=function(r){function t(){for(var e,t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return(e=r.call.apply(r,[this].concat(n))||this).handlePush=function(t){return e.navigateTo(t,"PUSH")},e.handleReplace=function(t){return e.navigateTo(t,"REPLACE")},e.handleListen=function(){return noop},e.handleBlock=function(){return noop},e}_inheritsLoose(t,r);var e=t.prototype;return e.navigateTo=function(t,e){var n=this.props,o=n.basename,r=void 0===o?"":o,a=n.context,i=void 0===a?{}:a;i.action=e,i.location=addBasename(r,history.createLocation(t)),i.url=createURL(i.location)},e.render=function(){var t=this.props,e=t.basename,n=void 0===e?"":e,o=t.context,r=void 0===o?{}:o,a=t.location,i=void 0===a?"/":a,c=_objectWithoutPropertiesLoose(t,["basename","context","location"]),u={createHref:function(t){return addLeadingSlash(n+createURL(t))},action:"POP",location:stripBasename(n,history.createLocation(i)),push:this.handlePush,replace:this.handleReplace,go:staticHandler("go"),goBack:staticHandler("goBack"),goForward:staticHandler("goForward"),listen:this.handleListen,block:this.handleBlock};return React.createElement(Router,_extends({},c,{history:u,staticContext:r}))},t}(React.Component),Switch=function(t){function e(){return t.apply(this,arguments)||this}return _inheritsLoose(e,t),e.prototype.render=function(){var t=this;return React.createElement(context.Consumer,null,function(n){n||invariant(!1);var o,r,a=t.props.location||n.location;return React.Children.forEach(t.props.children,function(t){if(null==r&&React.isValidElement(t)){var e=(o=t).props.path||t.props.from;r=e?matchPath(a.pathname,_extends({},t.props,{path:e})):n.match}}),r?React.cloneElement(o,{location:a,computedMatch:r}):null})},e}(React.Component);function withRouter(o){var t="withRouter("+(o.displayName||o.name)+")",e=function(t){var e=t.wrappedComponentRef,n=_objectWithoutPropertiesLoose(t,["wrappedComponentRef"]);return React.createElement(context.Consumer,null,function(t){return t||invariant(!1),React.createElement(o,_extends({},n,t,{ref:e}))})};return e.displayName=t,e.WrappedComponent=o,hoistStatics(e,o)}exports.MemoryRouter=MemoryRouter,exports.Prompt=Prompt,exports.Redirect=Redirect,exports.Route=Route,exports.Router=Router,exports.StaticRouter=StaticRouter,exports.Switch=Switch,exports.generatePath=generatePath,exports.matchPath=matchPath,exports.withRouter=withRouter,exports.__RouterContext=context;