react-router 4.4.0-beta.5 → 5.0.0

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):
@@ -5,13 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
7
  var createContext = _interopDefault(require('create-react-context'));
8
- var warning = _interopDefault(require('warning'));
9
8
  var React = _interopDefault(require('react'));
10
9
  var PropTypes = _interopDefault(require('prop-types'));
10
+ var warning = _interopDefault(require('tiny-warning'));
11
11
  var history = require('history');
12
- var invariant = _interopDefault(require('invariant'));
12
+ var invariant = _interopDefault(require('tiny-invariant'));
13
13
  var pathToRegexp = _interopDefault(require('path-to-regexp'));
14
- var ReactIs = _interopDefault(require('react-is'));
14
+ var reactIs = require('react-is');
15
15
  var hoistStatics = _interopDefault(require('hoist-non-react-statics'));
16
16
 
17
17
  function _extends() {
@@ -54,45 +54,22 @@ function _objectWithoutPropertiesLoose(source, excluded) {
54
54
  }
55
55
 
56
56
  // 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
57
 
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
- }
58
+ var createNamedContext = function createNamedContext(name) {
59
+ var context = createContext();
60
+ context.Provider.displayName = name + ".Provider";
61
+ context.Consumer.displayName = name + ".Consumer";
62
+ return context;
63
+ };
80
64
 
81
- var warnAboutGettingProperty$1 = warnAboutGettingProperty;
65
+ var context =
66
+ /*#__PURE__*/
67
+ createNamedContext('Router');
82
68
 
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
69
  /**
92
70
  * The public API for putting history on context.
93
71
  */
94
72
 
95
-
96
73
  var Router =
97
74
  /*#__PURE__*/
98
75
  function (_React$Component) {
@@ -154,39 +131,19 @@ function (_React$Component) {
154
131
  };
155
132
 
156
133
  _proto.render = function render() {
157
- var context$$1 = getContext(this.props, this.state);
158
134
  return React.createElement(context.Provider, {
159
135
  children: this.props.children || null,
160
- value: context$$1
136
+ value: {
137
+ history: this.props.history,
138
+ location: this.state.location,
139
+ match: Router.computeRootMatch(this.state.location.pathname),
140
+ staticContext: this.props.staticContext
141
+ }
161
142
  });
162
143
  };
163
144
 
164
145
  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
- }
146
+ }(React.Component);
190
147
 
191
148
  {
192
149
  Router.propTypes = {
@@ -281,12 +238,14 @@ function (_React$Component) {
281
238
  * The public API for prompting the user before navigating away from a screen.
282
239
  */
283
240
 
284
- function Prompt(props) {
241
+ function Prompt(_ref) {
242
+ var message = _ref.message,
243
+ _ref$when = _ref.when,
244
+ when = _ref$when === void 0 ? true : _ref$when;
285
245
  return React.createElement(context.Consumer, null, function (context$$1) {
286
246
  !context$$1 ? invariant(false, "You should not use <Prompt> outside a <Router>") : void 0;
287
- if (!props.when || context$$1.staticContext) return null;
247
+ if (!when || context$$1.staticContext) return null;
288
248
  var method = context$$1.history.block;
289
- var message = props.message;
290
249
  return React.createElement(Lifecycle, {
291
250
  onMount: function onMount(self) {
292
251
  self.release = method(message);
@@ -299,15 +258,12 @@ function Prompt(props) {
299
258
  },
300
259
  onUnmount: function onUnmount(self) {
301
260
  self.release();
302
- }
261
+ },
262
+ message: message
303
263
  });
304
264
  });
305
265
  }
306
266
 
307
- Prompt.defaultProps = {
308
- when: true
309
- };
310
-
311
267
  {
312
268
  var messageType = PropTypes.oneOfType([PropTypes.func, PropTypes.string]);
313
269
  Prompt.propTypes = {
@@ -354,27 +310,33 @@ function generatePath(path, params) {
354
310
  * The public API for navigating programmatically with a component.
355
311
  */
356
312
 
357
- function Redirect(props) {
313
+ function Redirect(_ref) {
314
+ var computedMatch = _ref.computedMatch,
315
+ to = _ref.to,
316
+ _ref$push = _ref.push,
317
+ push = _ref$push === void 0 ? false : _ref$push;
358
318
  return React.createElement(context.Consumer, null, function (context$$1) {
359
319
  !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,
320
+ var history$$1 = context$$1.history,
321
+ staticContext = context$$1.staticContext;
322
+ var method = push ? history$$1.push : history$$1.replace;
323
+ var location = history.createLocation(computedMatch ? typeof to === "string" ? generatePath(to, computedMatch.params) : _extends({}, to, {
324
+ pathname: generatePath(to.pathname, computedMatch.params)
325
+ }) : to); // When rendering in a static context,
364
326
  // set the new location immediately.
365
327
 
366
- if (context$$1.staticContext) {
367
- method(to);
328
+ if (staticContext) {
329
+ method(location);
368
330
  return null;
369
331
  }
370
332
 
371
333
  return React.createElement(Lifecycle, {
372
334
  onMount: function onMount() {
373
- method(to);
335
+ method(location);
374
336
  },
375
337
  onUpdate: function onUpdate(self, prevProps) {
376
- if (!history.locationsAreEqual(prevProps.to, to)) {
377
- method(to);
338
+ if (!history.locationsAreEqual(prevProps.to, location)) {
339
+ method(location);
378
340
  }
379
341
  },
380
342
  to: to
@@ -382,10 +344,6 @@ function Redirect(props) {
382
344
  });
383
345
  }
384
346
 
385
- Redirect.defaultProps = {
386
- push: false
387
- };
388
-
389
347
  {
390
348
  Redirect.propTypes = {
391
349
  push: PropTypes.bool,
@@ -473,16 +431,6 @@ function matchPath(pathname, options) {
473
431
  function isEmptyChildren(children) {
474
432
  return React.Children.count(children) === 0;
475
433
  }
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
434
  /**
487
435
  * The public API for matching a single path and rendering.
488
436
  */
@@ -504,7 +452,15 @@ function (_React$Component) {
504
452
 
505
453
  return React.createElement(context.Consumer, null, function (context$$1) {
506
454
  !context$$1 ? invariant(false, "You should not use <Route> outside a <Router>") : void 0;
507
- var props = getContext$1(_this.props, context$$1);
455
+ var location = _this.props.location || context$$1.location;
456
+ var match = _this.props.computedMatch ? _this.props.computedMatch // <Switch> already computed the match for us
457
+ : _this.props.path ? matchPath(location.pathname, _this.props) : context$$1.match;
458
+
459
+ var props = _extends({}, context$$1, {
460
+ location: location,
461
+ match: match
462
+ });
463
+
508
464
  var _this$props = _this.props,
509
465
  children = _this$props.children,
510
466
  component = _this$props.component,
@@ -535,47 +491,13 @@ function (_React$Component) {
535
491
  };
536
492
 
537
493
  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
- }
494
+ }(React.Component);
573
495
 
574
496
  {
575
497
  Route.propTypes = {
576
498
  children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
577
499
  component: function component(props, propName) {
578
- if (props[propName] && !ReactIs.isValidElementType(props[propName])) {
500
+ if (props[propName] && !reactIs.isValidElementType(props[propName])) {
579
501
  return new Error("Invalid prop 'component' supplied to 'Route': the prop is not a valid React component");
580
502
  }
581
503
  },
@@ -652,26 +574,12 @@ function (_React$Component) {
652
574
 
653
575
  _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
654
576
 
655
- _this.createHref = function (path) {
656
- return addLeadingSlash(_this.props.basename + createURL(path));
657
- };
658
-
659
577
  _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);
578
+ return _this.navigateTo(location, "PUSH");
666
579
  };
667
580
 
668
581
  _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);
582
+ return _this.navigateTo(location, "REPLACE");
675
583
  };
676
584
 
677
585
  _this.handleListen = function () {
@@ -687,15 +595,30 @@ function (_React$Component) {
687
595
 
688
596
  var _proto = StaticRouter.prototype;
689
597
 
598
+ _proto.navigateTo = function navigateTo(location, action) {
599
+ var _this$props = this.props,
600
+ _this$props$basename = _this$props.basename,
601
+ basename = _this$props$basename === void 0 ? "" : _this$props$basename,
602
+ context = _this$props.context;
603
+ context.action = action;
604
+ context.location = addBasename(basename, history.createLocation(location));
605
+ context.url = createURL(context.location);
606
+ };
607
+
690
608
  _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"]);
609
+ var _this$props2 = this.props,
610
+ _this$props2$basename = _this$props2.basename,
611
+ basename = _this$props2$basename === void 0 ? "" : _this$props2$basename,
612
+ _this$props2$context = _this$props2.context,
613
+ context = _this$props2$context === void 0 ? {} : _this$props2$context,
614
+ _this$props2$location = _this$props2.location,
615
+ location = _this$props2$location === void 0 ? "/" : _this$props2$location,
616
+ rest = _objectWithoutPropertiesLoose(_this$props2, ["basename", "context", "location"]);
696
617
 
697
618
  var history$$1 = {
698
- createHref: this.createHref,
619
+ createHref: function createHref(path) {
620
+ return addLeadingSlash(basename + createURL(path));
621
+ },
699
622
  action: "POP",
700
623
  location: stripBasename(basename, history.createLocation(location)),
701
624
  push: this.handlePush,
@@ -708,18 +631,13 @@ function (_React$Component) {
708
631
  };
709
632
  return React.createElement(Router, _extends({}, rest, {
710
633
  history: history$$1,
711
- staticContext: this.props.context || {}
634
+ staticContext: context
712
635
  }));
713
636
  };
714
637
 
715
638
  return StaticRouter;
716
639
  }(React.Component);
717
640
 
718
- StaticRouter.defaultProps = {
719
- basename: "",
720
- location: "/"
721
- };
722
-
723
641
  {
724
642
  StaticRouter.propTypes = {
725
643
  basename: PropTypes.string,
@@ -819,6 +737,28 @@ function withRouter(Component) {
819
737
  return hoistStatics(C, Component);
820
738
  }
821
739
 
740
+ {
741
+ if (typeof window !== "undefined") {
742
+ var global = window;
743
+ var key = "__react_router_build__";
744
+ var buildNames = {
745
+ cjs: "CommonJS",
746
+ esm: "ES modules",
747
+ umd: "UMD"
748
+ };
749
+
750
+ if (global[key] && global[key] !== "cjs") {
751
+ var initialBuildName = buildNames[global[key]];
752
+ var secondaryBuildName = buildNames["cjs"]; // TODO: Add link to article that explains in detail how to avoid
753
+ // loading 2 different builds.
754
+
755
+ 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.");
756
+ }
757
+
758
+ global[key] = "cjs";
759
+ }
760
+ }
761
+
822
762
  exports.MemoryRouter = MemoryRouter;
823
763
  exports.Prompt = Prompt;
824
764
  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("warning");var React=_interopDefault(require("react")),PropTypes=_interopDefault(require("prop-types")),history=require("history"),invariant=_interopDefault(require("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("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.Provider.displayName=t+".Provider",e.Consumer.displayName=t+".Consumer",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){history.locationsAreEqual(e.to,r)||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(u,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(u);if(!a)return null;var i=a[0],c=a.slice(1),s=u===i;return p&&!s?null:{path:e,url:"/"===e&&""===i?"/":i,isExact:s,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;a.action=e,a.location=addBasename(r,history.createLocation(t)),a.url=createURL(a.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"]),s={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:s,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=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;