25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

3789 lines
124 KiB

  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
  4. (factory((global.ReactRouterDOM = {}),global.React));
  5. }(this, (function (exports,React) { 'use strict';
  6. React = React && React.hasOwnProperty('default') ? React['default'] : React;
  7. /**
  8. * Copyright (c) 2014-present, Facebook, Inc.
  9. *
  10. * This source code is licensed under the MIT license found in the
  11. * LICENSE file in the root directory of this source tree.
  12. *
  13. * @providesModule warning
  14. */
  15. var warning = function () {};
  16. {
  17. var printWarning = function printWarning(format, args) {
  18. var len = arguments.length;
  19. args = new Array(len > 2 ? len - 2 : 0);
  20. for (var key = 2; key < len; key++) {
  21. args[key - 2] = arguments[key];
  22. }
  23. var argIndex = 0;
  24. var message = 'Warning: ' + format.replace(/%s/g, function () {
  25. return args[argIndex++];
  26. });
  27. if (typeof console !== 'undefined') {
  28. console.error(message);
  29. }
  30. try {
  31. // --- Welcome to debugging React ---
  32. // This error was thrown as a convenience so that you can use this stack
  33. // to find the callsite that caused this warning to fire.
  34. throw new Error(message);
  35. } catch (x) {}
  36. };
  37. warning = function (condition, format, args) {
  38. var len = arguments.length;
  39. args = new Array(len > 2 ? len - 2 : 0);
  40. for (var key = 2; key < len; key++) {
  41. args[key - 2] = arguments[key];
  42. }
  43. if (format === undefined) {
  44. throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
  45. }
  46. if (!condition) {
  47. printWarning.apply(null, [format].concat(args));
  48. }
  49. };
  50. }
  51. var warning_1 = warning;
  52. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  53. function createCommonjsModule(fn, module) {
  54. return module = { exports: {} }, fn(module, module.exports), module.exports;
  55. }
  56. /**
  57. * Copyright (c) 2013-present, Facebook, Inc.
  58. *
  59. * This source code is licensed under the MIT license found in the
  60. * LICENSE file in the root directory of this source tree.
  61. *
  62. *
  63. */
  64. function makeEmptyFunction(arg) {
  65. return function () {
  66. return arg;
  67. };
  68. }
  69. /**
  70. * This function accepts and discards inputs; it has no side effects. This is
  71. * primarily useful idiomatically for overridable function endpoints which
  72. * always need to be callable, since JS lacks a null-call idiom ala Cocoa.
  73. */
  74. var emptyFunction = function emptyFunction() {};
  75. emptyFunction.thatReturns = makeEmptyFunction;
  76. emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
  77. emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
  78. emptyFunction.thatReturnsNull = makeEmptyFunction(null);
  79. emptyFunction.thatReturnsThis = function () {
  80. return this;
  81. };
  82. emptyFunction.thatReturnsArgument = function (arg) {
  83. return arg;
  84. };
  85. var emptyFunction_1 = emptyFunction;
  86. /**
  87. * Copyright (c) 2013-present, Facebook, Inc.
  88. *
  89. * This source code is licensed under the MIT license found in the
  90. * LICENSE file in the root directory of this source tree.
  91. *
  92. */
  93. /**
  94. * Use invariant() to assert state which your program assumes to be true.
  95. *
  96. * Provide sprintf-style format (only %s is supported) and arguments
  97. * to provide information about what broke and what you were
  98. * expecting.
  99. *
  100. * The invariant message will be stripped in production, but the invariant
  101. * will remain to ensure logic does not differ in production.
  102. */
  103. var validateFormat = function validateFormat(format) {};
  104. {
  105. validateFormat = function validateFormat(format) {
  106. if (format === undefined) {
  107. throw new Error('invariant requires an error message argument');
  108. }
  109. };
  110. }
  111. function invariant(condition, format, a, b, c, d, e, f) {
  112. validateFormat(format);
  113. if (!condition) {
  114. var error;
  115. if (format === undefined) {
  116. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  117. } else {
  118. var args = [a, b, c, d, e, f];
  119. var argIndex = 0;
  120. error = new Error(format.replace(/%s/g, function () {
  121. return args[argIndex++];
  122. }));
  123. error.name = 'Invariant Violation';
  124. }
  125. error.framesToPop = 1; // we don't care about invariant's own frame
  126. throw error;
  127. }
  128. }
  129. var invariant_1 = invariant;
  130. /**
  131. * Similar to invariant but only logs a warning if the condition is not met.
  132. * This can be used to log issues in development environments in critical
  133. * paths. Removing the logging code for production environments will keep the
  134. * same logic and follow the same code paths.
  135. */
  136. var warning$1 = emptyFunction_1;
  137. {
  138. var printWarning$1 = function printWarning(format) {
  139. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  140. args[_key - 1] = arguments[_key];
  141. }
  142. var argIndex = 0;
  143. var message = 'Warning: ' + format.replace(/%s/g, function () {
  144. return args[argIndex++];
  145. });
  146. if (typeof console !== 'undefined') {
  147. console.error(message);
  148. }
  149. try {
  150. // --- Welcome to debugging React ---
  151. // This error was thrown as a convenience so that you can use this stack
  152. // to find the callsite that caused this warning to fire.
  153. throw new Error(message);
  154. } catch (x) {}
  155. };
  156. warning$1 = function warning(condition, format) {
  157. if (format === undefined) {
  158. throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
  159. }
  160. if (format.indexOf('Failed Composite propType: ') === 0) {
  161. return; // Ignore CompositeComponent proptype check.
  162. }
  163. if (!condition) {
  164. for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
  165. args[_key2 - 2] = arguments[_key2];
  166. }
  167. printWarning$1.apply(undefined, [format].concat(args));
  168. }
  169. };
  170. }
  171. var warning_1$1 = warning$1;
  172. /*
  173. object-assign
  174. (c) Sindre Sorhus
  175. @license MIT
  176. */
  177. /* eslint-disable no-unused-vars */
  178. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  179. var hasOwnProperty = Object.prototype.hasOwnProperty;
  180. var propIsEnumerable = Object.prototype.propertyIsEnumerable;
  181. function toObject(val) {
  182. if (val === null || val === undefined) {
  183. throw new TypeError('Object.assign cannot be called with null or undefined');
  184. }
  185. return Object(val);
  186. }
  187. function shouldUseNative() {
  188. try {
  189. if (!Object.assign) {
  190. return false;
  191. }
  192. // Detect buggy property enumeration order in older V8 versions.
  193. // https://bugs.chromium.org/p/v8/issues/detail?id=4118
  194. var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
  195. test1[5] = 'de';
  196. if (Object.getOwnPropertyNames(test1)[0] === '5') {
  197. return false;
  198. }
  199. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  200. var test2 = {};
  201. for (var i = 0; i < 10; i++) {
  202. test2['_' + String.fromCharCode(i)] = i;
  203. }
  204. var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
  205. return test2[n];
  206. });
  207. if (order2.join('') !== '0123456789') {
  208. return false;
  209. }
  210. // https://bugs.chromium.org/p/v8/issues/detail?id=3056
  211. var test3 = {};
  212. 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
  213. test3[letter] = letter;
  214. });
  215. if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
  216. return false;
  217. }
  218. return true;
  219. } catch (err) {
  220. // We don't expect any of the above to throw, but better to be safe.
  221. return false;
  222. }
  223. }
  224. var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
  225. var from;
  226. var to = toObject(target);
  227. var symbols;
  228. for (var s = 1; s < arguments.length; s++) {
  229. from = Object(arguments[s]);
  230. for (var key in from) {
  231. if (hasOwnProperty.call(from, key)) {
  232. to[key] = from[key];
  233. }
  234. }
  235. if (getOwnPropertySymbols) {
  236. symbols = getOwnPropertySymbols(from);
  237. for (var i = 0; i < symbols.length; i++) {
  238. if (propIsEnumerable.call(from, symbols[i])) {
  239. to[symbols[i]] = from[symbols[i]];
  240. }
  241. }
  242. }
  243. }
  244. return to;
  245. };
  246. /**
  247. * Copyright (c) 2013-present, Facebook, Inc.
  248. *
  249. * This source code is licensed under the MIT license found in the
  250. * LICENSE file in the root directory of this source tree.
  251. */
  252. var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
  253. var ReactPropTypesSecret_1 = ReactPropTypesSecret;
  254. {
  255. var invariant$1 = invariant_1;
  256. var warning$2 = warning_1$1;
  257. var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
  258. var loggedTypeFailures = {};
  259. }
  260. /**
  261. * Assert that the values match with the type specs.
  262. * Error messages are memorized and will only be shown once.
  263. *
  264. * @param {object} typeSpecs Map of name to a ReactPropType
  265. * @param {object} values Runtime values that need to be type-checked
  266. * @param {string} location e.g. "prop", "context", "child context"
  267. * @param {string} componentName Name of the component for error messages.
  268. * @param {?Function} getStack Returns the component stack.
  269. * @private
  270. */
  271. function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
  272. {
  273. for (var typeSpecName in typeSpecs) {
  274. if (typeSpecs.hasOwnProperty(typeSpecName)) {
  275. var error;
  276. // Prop type validation may throw. In case they do, we don't want to
  277. // fail the render phase where it didn't fail before. So we log it.
  278. // After these have been cleaned up, we'll let them throw.
  279. try {
  280. // This is intentionally an invariant that gets caught. It's the same
  281. // behavior as without this statement except with a better message.
  282. invariant$1(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]);
  283. error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
  284. } catch (ex) {
  285. error = ex;
  286. }
  287. warning$2(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error);
  288. if (error instanceof Error && !(error.message in loggedTypeFailures)) {
  289. // Only monitor this failure once because there tends to be a lot of the
  290. // same error.
  291. loggedTypeFailures[error.message] = true;
  292. var stack = getStack ? getStack() : '';
  293. warning$2(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
  294. }
  295. }
  296. }
  297. }
  298. }
  299. var checkPropTypes_1 = checkPropTypes;
  300. var factoryWithTypeCheckers = function (isValidElement, throwOnDirectAccess) {
  301. /* global Symbol */
  302. var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
  303. var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
  304. /**
  305. * Returns the iterator method function contained on the iterable object.
  306. *
  307. * Be sure to invoke the function with the iterable as context:
  308. *
  309. * var iteratorFn = getIteratorFn(myIterable);
  310. * if (iteratorFn) {
  311. * var iterator = iteratorFn.call(myIterable);
  312. * ...
  313. * }
  314. *
  315. * @param {?object} maybeIterable
  316. * @return {?function}
  317. */
  318. function getIteratorFn(maybeIterable) {
  319. var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
  320. if (typeof iteratorFn === 'function') {
  321. return iteratorFn;
  322. }
  323. }
  324. /**
  325. * Collection of methods that allow declaration and validation of props that are
  326. * supplied to React components. Example usage:
  327. *
  328. * var Props = require('ReactPropTypes');
  329. * var MyArticle = React.createClass({
  330. * propTypes: {
  331. * // An optional string prop named "description".
  332. * description: Props.string,
  333. *
  334. * // A required enum prop named "category".
  335. * category: Props.oneOf(['News','Photos']).isRequired,
  336. *
  337. * // A prop named "dialog" that requires an instance of Dialog.
  338. * dialog: Props.instanceOf(Dialog).isRequired
  339. * },
  340. * render: function() { ... }
  341. * });
  342. *
  343. * A more formal specification of how these methods are used:
  344. *
  345. * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
  346. * decl := ReactPropTypes.{type}(.isRequired)?
  347. *
  348. * Each and every declaration produces a function with the same signature. This
  349. * allows the creation of custom validation functions. For example:
  350. *
  351. * var MyLink = React.createClass({
  352. * propTypes: {
  353. * // An optional string or URI prop named "href".
  354. * href: function(props, propName, componentName) {
  355. * var propValue = props[propName];
  356. * if (propValue != null && typeof propValue !== 'string' &&
  357. * !(propValue instanceof URI)) {
  358. * return new Error(
  359. * 'Expected a string or an URI for ' + propName + ' in ' +
  360. * componentName
  361. * );
  362. * }
  363. * }
  364. * },
  365. * render: function() {...}
  366. * });
  367. *
  368. * @internal
  369. */
  370. var ANONYMOUS = '<<anonymous>>';
  371. // Important!
  372. // Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
  373. var ReactPropTypes = {
  374. array: createPrimitiveTypeChecker('array'),
  375. bool: createPrimitiveTypeChecker('boolean'),
  376. func: createPrimitiveTypeChecker('function'),
  377. number: createPrimitiveTypeChecker('number'),
  378. object: createPrimitiveTypeChecker('object'),
  379. string: createPrimitiveTypeChecker('string'),
  380. symbol: createPrimitiveTypeChecker('symbol'),
  381. any: createAnyTypeChecker(),
  382. arrayOf: createArrayOfTypeChecker,
  383. element: createElementTypeChecker(),
  384. instanceOf: createInstanceTypeChecker,
  385. node: createNodeChecker(),
  386. objectOf: createObjectOfTypeChecker,
  387. oneOf: createEnumTypeChecker,
  388. oneOfType: createUnionTypeChecker,
  389. shape: createShapeTypeChecker,
  390. exact: createStrictShapeTypeChecker
  391. };
  392. /**
  393. * inlined Object.is polyfill to avoid requiring consumers ship their own
  394. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  395. */
  396. /*eslint-disable no-self-compare*/
  397. function is(x, y) {
  398. // SameValue algorithm
  399. if (x === y) {
  400. // Steps 1-5, 7-10
  401. // Steps 6.b-6.e: +0 != -0
  402. return x !== 0 || 1 / x === 1 / y;
  403. } else {
  404. // Step 6.a: NaN == NaN
  405. return x !== x && y !== y;
  406. }
  407. }
  408. /*eslint-enable no-self-compare*/
  409. /**
  410. * We use an Error-like object for backward compatibility as people may call
  411. * PropTypes directly and inspect their output. However, we don't use real
  412. * Errors anymore. We don't inspect their stack anyway, and creating them
  413. * is prohibitively expensive if they are created too often, such as what
  414. * happens in oneOfType() for any type before the one that matched.
  415. */
  416. function PropTypeError(message) {
  417. this.message = message;
  418. this.stack = '';
  419. }
  420. // Make `instanceof Error` still work for returned errors.
  421. PropTypeError.prototype = Error.prototype;
  422. function createChainableTypeChecker(validate) {
  423. {
  424. var manualPropTypeCallCache = {};
  425. var manualPropTypeWarningCount = 0;
  426. }
  427. function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
  428. componentName = componentName || ANONYMOUS;
  429. propFullName = propFullName || propName;
  430. if (secret !== ReactPropTypesSecret_1) {
  431. if (throwOnDirectAccess) {
  432. // New behavior only for users of `prop-types` package
  433. invariant_1(false, 'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + 'Use `PropTypes.checkPropTypes()` to call them. ' + 'Read more at http://fb.me/use-check-prop-types');
  434. } else if (typeof console !== 'undefined') {
  435. // Old behavior for people using React.PropTypes
  436. var cacheKey = componentName + ':' + propName;
  437. if (!manualPropTypeCallCache[cacheKey] &&
  438. // Avoid spamming the console because they are often not actionable except for lib authors
  439. manualPropTypeWarningCount < 3) {
  440. warning_1$1(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will throw in the standalone `prop-types` package. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName);
  441. manualPropTypeCallCache[cacheKey] = true;
  442. manualPropTypeWarningCount++;
  443. }
  444. }
  445. }
  446. if (props[propName] == null) {
  447. if (isRequired) {
  448. if (props[propName] === null) {
  449. return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
  450. }
  451. return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
  452. }
  453. return null;
  454. } else {
  455. return validate(props, propName, componentName, location, propFullName);
  456. }
  457. }
  458. var chainedCheckType = checkType.bind(null, false);
  459. chainedCheckType.isRequired = checkType.bind(null, true);
  460. return chainedCheckType;
  461. }
  462. function createPrimitiveTypeChecker(expectedType) {
  463. function validate(props, propName, componentName, location, propFullName, secret) {
  464. var propValue = props[propName];
  465. var propType = getPropType(propValue);
  466. if (propType !== expectedType) {
  467. // `propValue` being instance of, say, date/regexp, pass the 'object'
  468. // check, but we can offer a more precise error message here rather than
  469. // 'of type `object`'.
  470. var preciseType = getPreciseType(propValue);
  471. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
  472. }
  473. return null;
  474. }
  475. return createChainableTypeChecker(validate);
  476. }
  477. function createAnyTypeChecker() {
  478. return createChainableTypeChecker(emptyFunction_1.thatReturnsNull);
  479. }
  480. function createArrayOfTypeChecker(typeChecker) {
  481. function validate(props, propName, componentName, location, propFullName) {
  482. if (typeof typeChecker !== 'function') {
  483. return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
  484. }
  485. var propValue = props[propName];
  486. if (!Array.isArray(propValue)) {
  487. var propType = getPropType(propValue);
  488. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
  489. }
  490. for (var i = 0; i < propValue.length; i++) {
  491. var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
  492. if (error instanceof Error) {
  493. return error;
  494. }
  495. }
  496. return null;
  497. }
  498. return createChainableTypeChecker(validate);
  499. }
  500. function createElementTypeChecker() {
  501. function validate(props, propName, componentName, location, propFullName) {
  502. var propValue = props[propName];
  503. if (!isValidElement(propValue)) {
  504. var propType = getPropType(propValue);
  505. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
  506. }
  507. return null;
  508. }
  509. return createChainableTypeChecker(validate);
  510. }
  511. function createInstanceTypeChecker(expectedClass) {
  512. function validate(props, propName, componentName, location, propFullName) {
  513. if (!(props[propName] instanceof expectedClass)) {
  514. var expectedClassName = expectedClass.name || ANONYMOUS;
  515. var actualClassName = getClassName(props[propName]);
  516. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
  517. }
  518. return null;
  519. }
  520. return createChainableTypeChecker(validate);
  521. }
  522. function createEnumTypeChecker(expectedValues) {
  523. if (!Array.isArray(expectedValues)) {
  524. warning_1$1(false, 'Invalid argument supplied to oneOf, expected an instance of array.');
  525. return emptyFunction_1.thatReturnsNull;
  526. }
  527. function validate(props, propName, componentName, location, propFullName) {
  528. var propValue = props[propName];
  529. for (var i = 0; i < expectedValues.length; i++) {
  530. if (is(propValue, expectedValues[i])) {
  531. return null;
  532. }
  533. }
  534. var valuesString = JSON.stringify(expectedValues);
  535. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
  536. }
  537. return createChainableTypeChecker(validate);
  538. }
  539. function createObjectOfTypeChecker(typeChecker) {
  540. function validate(props, propName, componentName, location, propFullName) {
  541. if (typeof typeChecker !== 'function') {
  542. return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
  543. }
  544. var propValue = props[propName];
  545. var propType = getPropType(propValue);
  546. if (propType !== 'object') {
  547. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
  548. }
  549. for (var key in propValue) {
  550. if (propValue.hasOwnProperty(key)) {
  551. var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  552. if (error instanceof Error) {
  553. return error;
  554. }
  555. }
  556. }
  557. return null;
  558. }
  559. return createChainableTypeChecker(validate);
  560. }
  561. function createUnionTypeChecker(arrayOfTypeCheckers) {
  562. if (!Array.isArray(arrayOfTypeCheckers)) {
  563. warning_1$1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.');
  564. return emptyFunction_1.thatReturnsNull;
  565. }
  566. for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
  567. var checker = arrayOfTypeCheckers[i];
  568. if (typeof checker !== 'function') {
  569. warning_1$1(false, 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 'received %s at index %s.', getPostfixForTypeWarning(checker), i);
  570. return emptyFunction_1.thatReturnsNull;
  571. }
  572. }
  573. function validate(props, propName, componentName, location, propFullName) {
  574. for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
  575. var checker = arrayOfTypeCheckers[i];
  576. if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret_1) == null) {
  577. return null;
  578. }
  579. }
  580. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
  581. }
  582. return createChainableTypeChecker(validate);
  583. }
  584. function createNodeChecker() {
  585. function validate(props, propName, componentName, location, propFullName) {
  586. if (!isNode(props[propName])) {
  587. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
  588. }
  589. return null;
  590. }
  591. return createChainableTypeChecker(validate);
  592. }
  593. function createShapeTypeChecker(shapeTypes) {
  594. function validate(props, propName, componentName, location, propFullName) {
  595. var propValue = props[propName];
  596. var propType = getPropType(propValue);
  597. if (propType !== 'object') {
  598. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
  599. }
  600. for (var key in shapeTypes) {
  601. var checker = shapeTypes[key];
  602. if (!checker) {
  603. continue;
  604. }
  605. var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  606. if (error) {
  607. return error;
  608. }
  609. }
  610. return null;
  611. }
  612. return createChainableTypeChecker(validate);
  613. }
  614. function createStrictShapeTypeChecker(shapeTypes) {
  615. function validate(props, propName, componentName, location, propFullName) {
  616. var propValue = props[propName];
  617. var propType = getPropType(propValue);
  618. if (propType !== 'object') {
  619. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
  620. }
  621. // We need to check all keys in case some are required but missing from
  622. // props.
  623. var allKeys = objectAssign({}, props[propName], shapeTypes);
  624. for (var key in allKeys) {
  625. var checker = shapeTypes[key];
  626. if (!checker) {
  627. return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' '));
  628. }
  629. var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
  630. if (error) {
  631. return error;
  632. }
  633. }
  634. return null;
  635. }
  636. return createChainableTypeChecker(validate);
  637. }
  638. function isNode(propValue) {
  639. switch (typeof propValue) {
  640. case 'number':
  641. case 'string':
  642. case 'undefined':
  643. return true;
  644. case 'boolean':
  645. return !propValue;
  646. case 'object':
  647. if (Array.isArray(propValue)) {
  648. return propValue.every(isNode);
  649. }
  650. if (propValue === null || isValidElement(propValue)) {
  651. return true;
  652. }
  653. var iteratorFn = getIteratorFn(propValue);
  654. if (iteratorFn) {
  655. var iterator = iteratorFn.call(propValue);
  656. var step;
  657. if (iteratorFn !== propValue.entries) {
  658. while (!(step = iterator.next()).done) {
  659. if (!isNode(step.value)) {
  660. return false;
  661. }
  662. }
  663. } else {
  664. // Iterator will provide entry [k,v] tuples rather than values.
  665. while (!(step = iterator.next()).done) {
  666. var entry = step.value;
  667. if (entry) {
  668. if (!isNode(entry[1])) {
  669. return false;
  670. }
  671. }
  672. }
  673. }
  674. } else {
  675. return false;
  676. }
  677. return true;
  678. default:
  679. return false;
  680. }
  681. }
  682. function isSymbol(propType, propValue) {
  683. // Native Symbol.
  684. if (propType === 'symbol') {
  685. return true;
  686. }
  687. // 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
  688. if (propValue['@@toStringTag'] === 'Symbol') {
  689. return true;
  690. }
  691. // Fallback for non-spec compliant Symbols which are polyfilled.
  692. if (typeof Symbol === 'function' && propValue instanceof Symbol) {
  693. return true;
  694. }
  695. return false;
  696. }
  697. // Equivalent of `typeof` but with special handling for array and regexp.
  698. function getPropType(propValue) {
  699. var propType = typeof propValue;
  700. if (Array.isArray(propValue)) {
  701. return 'array';
  702. }
  703. if (propValue instanceof RegExp) {
  704. // Old webkits (at least until Android 4.0) return 'function' rather than
  705. // 'object' for typeof a RegExp. We'll normalize this here so that /bla/
  706. // passes PropTypes.object.
  707. return 'object';
  708. }
  709. if (isSymbol(propType, propValue)) {
  710. return 'symbol';
  711. }
  712. return propType;
  713. }
  714. // This handles more types than `getPropType`. Only used for error messages.
  715. // See `createPrimitiveTypeChecker`.
  716. function getPreciseType(propValue) {
  717. if (typeof propValue === 'undefined' || propValue === null) {
  718. return '' + propValue;
  719. }
  720. var propType = getPropType(propValue);
  721. if (propType === 'object') {
  722. if (propValue instanceof Date) {
  723. return 'date';
  724. } else if (propValue instanceof RegExp) {
  725. return 'regexp';
  726. }
  727. }
  728. return propType;
  729. }
  730. // Returns a string that is postfixed to a warning about an invalid type.
  731. // For example, "undefined" or "of type array"
  732. function getPostfixForTypeWarning(value) {
  733. var type = getPreciseType(value);
  734. switch (type) {
  735. case 'array':
  736. case 'object':
  737. return 'an ' + type;
  738. case 'boolean':
  739. case 'date':
  740. case 'regexp':
  741. return 'a ' + type;
  742. default:
  743. return type;
  744. }
  745. }
  746. // Returns class name of the object, if any.
  747. function getClassName(propValue) {
  748. if (!propValue.constructor || !propValue.constructor.name) {
  749. return ANONYMOUS;
  750. }
  751. return propValue.constructor.name;
  752. }
  753. ReactPropTypes.checkPropTypes = checkPropTypes_1;
  754. ReactPropTypes.PropTypes = ReactPropTypes;
  755. return ReactPropTypes;
  756. };
  757. var propTypes = createCommonjsModule(function (module) {
  758. /**
  759. * Copyright (c) 2013-present, Facebook, Inc.
  760. *
  761. * This source code is licensed under the MIT license found in the
  762. * LICENSE file in the root directory of this source tree.
  763. */
  764. {
  765. var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element') || 0xeac7;
  766. var isValidElement = function (object) {
  767. return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
  768. };
  769. // By explicitly using `prop-types` you are opting into new development behavior.
  770. // http://fb.me/prop-types-in-prod
  771. var throwOnDirectAccess = true;
  772. module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess);
  773. }
  774. });
  775. /**
  776. * Copyright (c) 2013-present, Facebook, Inc.
  777. *
  778. * This source code is licensed under the MIT license found in the
  779. * LICENSE file in the root directory of this source tree.
  780. */
  781. var invariant$2 = function (condition, format, a, b, c, d, e, f) {
  782. {
  783. if (format === undefined) {
  784. throw new Error('invariant requires an error message argument');
  785. }
  786. }
  787. if (!condition) {
  788. var error;
  789. if (format === undefined) {
  790. error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
  791. } else {
  792. var args = [a, b, c, d, e, f];
  793. var argIndex = 0;
  794. error = new Error(format.replace(/%s/g, function () {
  795. return args[argIndex++];
  796. }));
  797. error.name = 'Invariant Violation';
  798. }
  799. error.framesToPop = 1; // we don't care about invariant's own frame
  800. throw error;
  801. }
  802. };
  803. var invariant_1$1 = invariant$2;
  804. function isAbsolute(pathname) {
  805. return pathname.charAt(0) === '/';
  806. }
  807. // About 1.5x faster than the two-arg version of Array#splice()
  808. function spliceOne(list, index) {
  809. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1) {
  810. list[i] = list[k];
  811. }
  812. list.pop();
  813. }
  814. // This implementation is based heavily on node's url.parse
  815. function resolvePathname(to) {
  816. var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  817. var toParts = to && to.split('/') || [];
  818. var fromParts = from && from.split('/') || [];
  819. var isToAbs = to && isAbsolute(to);
  820. var isFromAbs = from && isAbsolute(from);
  821. var mustEndAbs = isToAbs || isFromAbs;
  822. if (to && isAbsolute(to)) {
  823. // to is absolute
  824. fromParts = toParts;
  825. } else if (toParts.length) {
  826. // to is relative, drop the filename
  827. fromParts.pop();
  828. fromParts = fromParts.concat(toParts);
  829. }
  830. if (!fromParts.length) return '/';
  831. var hasTrailingSlash = void 0;
  832. if (fromParts.length) {
  833. var last = fromParts[fromParts.length - 1];
  834. hasTrailingSlash = last === '.' || last === '..' || last === '';
  835. } else {
  836. hasTrailingSlash = false;
  837. }
  838. var up = 0;
  839. for (var i = fromParts.length; i >= 0; i--) {
  840. var part = fromParts[i];
  841. if (part === '.') {
  842. spliceOne(fromParts, i);
  843. } else if (part === '..') {
  844. spliceOne(fromParts, i);
  845. up++;
  846. } else if (up) {
  847. spliceOne(fromParts, i);
  848. up--;
  849. }
  850. }
  851. if (!mustEndAbs) for (; up--; up) {
  852. fromParts.unshift('..');
  853. }if (mustEndAbs && fromParts[0] !== '' && (!fromParts[0] || !isAbsolute(fromParts[0]))) fromParts.unshift('');
  854. var result = fromParts.join('/');
  855. if (hasTrailingSlash && result.substr(-1) !== '/') result += '/';
  856. return result;
  857. }
  858. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  859. return typeof obj;
  860. } : function (obj) {
  861. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  862. };
  863. function valueEqual(a, b) {
  864. if (a === b) return true;
  865. if (a == null || b == null) return false;
  866. if (Array.isArray(a)) {
  867. return Array.isArray(b) && a.length === b.length && a.every(function (item, index) {
  868. return valueEqual(item, b[index]);
  869. });
  870. }
  871. var aType = typeof a === 'undefined' ? 'undefined' : _typeof(a);
  872. var bType = typeof b === 'undefined' ? 'undefined' : _typeof(b);
  873. if (aType !== bType) return false;
  874. if (aType === 'object') {
  875. var aValue = a.valueOf();
  876. var bValue = b.valueOf();
  877. if (aValue !== a || bValue !== b) return valueEqual(aValue, bValue);
  878. var aKeys = Object.keys(a);
  879. var bKeys = Object.keys(b);
  880. if (aKeys.length !== bKeys.length) return false;
  881. return aKeys.every(function (key) {
  882. return valueEqual(a[key], b[key]);
  883. });
  884. }
  885. return false;
  886. }
  887. var addLeadingSlash = function addLeadingSlash(path) {
  888. return path.charAt(0) === '/' ? path : '/' + path;
  889. };
  890. var stripLeadingSlash = function stripLeadingSlash(path) {
  891. return path.charAt(0) === '/' ? path.substr(1) : path;
  892. };
  893. var hasBasename = function hasBasename(path, prefix) {
  894. return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
  895. };
  896. var stripBasename = function stripBasename(path, prefix) {
  897. return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
  898. };
  899. var stripTrailingSlash = function stripTrailingSlash(path) {
  900. return path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path;
  901. };
  902. var parsePath = function parsePath(path) {
  903. var pathname = path || '/';
  904. var search = '';
  905. var hash = '';
  906. var hashIndex = pathname.indexOf('#');
  907. if (hashIndex !== -1) {
  908. hash = pathname.substr(hashIndex);
  909. pathname = pathname.substr(0, hashIndex);
  910. }
  911. var searchIndex = pathname.indexOf('?');
  912. if (searchIndex !== -1) {
  913. search = pathname.substr(searchIndex);
  914. pathname = pathname.substr(0, searchIndex);
  915. }
  916. return {
  917. pathname: pathname,
  918. search: search === '?' ? '' : search,
  919. hash: hash === '#' ? '' : hash
  920. };
  921. };
  922. var createPath = function createPath(location) {
  923. var pathname = location.pathname,
  924. search = location.search,
  925. hash = location.hash;
  926. var path = pathname || '/';
  927. if (search && search !== '?') path += search.charAt(0) === '?' ? search : '?' + search;
  928. if (hash && hash !== '#') path += hash.charAt(0) === '#' ? hash : '#' + hash;
  929. return path;
  930. };
  931. var _extends = Object.assign || function (target) {
  932. for (var i = 1; i < arguments.length; i++) {
  933. var source = arguments[i];for (var key in source) {
  934. if (Object.prototype.hasOwnProperty.call(source, key)) {
  935. target[key] = source[key];
  936. }
  937. }
  938. }return target;
  939. };
  940. var createLocation = function createLocation(path, state, key, currentLocation) {
  941. var location = void 0;
  942. if (typeof path === 'string') {
  943. // Two-arg form: push(path, state)
  944. location = parsePath(path);
  945. location.state = state;
  946. } else {
  947. // One-arg form: push(location)
  948. location = _extends({}, path);
  949. if (location.pathname === undefined) location.pathname = '';
  950. if (location.search) {
  951. if (location.search.charAt(0) !== '?') location.search = '?' + location.search;
  952. } else {
  953. location.search = '';
  954. }
  955. if (location.hash) {
  956. if (location.hash.charAt(0) !== '#') location.hash = '#' + location.hash;
  957. } else {
  958. location.hash = '';
  959. }
  960. if (state !== undefined && location.state === undefined) location.state = state;
  961. }
  962. try {
  963. location.pathname = decodeURI(location.pathname);
  964. } catch (e) {
  965. if (e instanceof URIError) {
  966. throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + 'This is likely caused by an invalid percent-encoding.');
  967. } else {
  968. throw e;
  969. }
  970. }
  971. if (key) location.key = key;
  972. if (currentLocation) {
  973. // Resolve incomplete/relative pathname relative to current location.
  974. if (!location.pathname) {
  975. location.pathname = currentLocation.pathname;
  976. } else if (location.pathname.charAt(0) !== '/') {
  977. location.pathname = resolvePathname(location.pathname, currentLocation.pathname);
  978. }
  979. } else {
  980. // When there is no prior location and pathname is empty, set it to /
  981. if (!location.pathname) {
  982. location.pathname = '/';
  983. }
  984. }
  985. return location;
  986. };
  987. var locationsAreEqual = function locationsAreEqual(a, b) {
  988. return a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && a.key === b.key && valueEqual(a.state, b.state);
  989. };
  990. var createTransitionManager = function createTransitionManager() {
  991. var prompt = null;
  992. var setPrompt = function setPrompt(nextPrompt) {
  993. warning_1(prompt == null, 'A history supports only one prompt at a time');
  994. prompt = nextPrompt;
  995. return function () {
  996. if (prompt === nextPrompt) prompt = null;
  997. };
  998. };
  999. var confirmTransitionTo = function confirmTransitionTo(location, action, getUserConfirmation, callback) {
  1000. // TODO: If another transition starts while we're still confirming
  1001. // the previous one, we may end up in a weird state. Figure out the
  1002. // best way to handle this.
  1003. if (prompt != null) {
  1004. var result = typeof prompt === 'function' ? prompt(location, action) : prompt;
  1005. if (typeof result === 'string') {
  1006. if (typeof getUserConfirmation === 'function') {
  1007. getUserConfirmation(result, callback);
  1008. } else {
  1009. warning_1(false, 'A history needs a getUserConfirmation function in order to use a prompt message');
  1010. callback(true);
  1011. }
  1012. } else {
  1013. // Return false from a transition hook to cancel the transition.
  1014. callback(result !== false);
  1015. }
  1016. } else {
  1017. callback(true);
  1018. }
  1019. };
  1020. var listeners = [];
  1021. var appendListener = function appendListener(fn) {
  1022. var isActive = true;
  1023. var listener = function listener() {
  1024. if (isActive) fn.apply(undefined, arguments);
  1025. };
  1026. listeners.push(listener);
  1027. return function () {
  1028. isActive = false;
  1029. listeners = listeners.filter(function (item) {
  1030. return item !== listener;
  1031. });
  1032. };
  1033. };
  1034. var notifyListeners = function notifyListeners() {
  1035. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1036. args[_key] = arguments[_key];
  1037. }
  1038. listeners.forEach(function (listener) {
  1039. return listener.apply(undefined, args);
  1040. });
  1041. };
  1042. return {
  1043. setPrompt: setPrompt,
  1044. confirmTransitionTo: confirmTransitionTo,
  1045. appendListener: appendListener,
  1046. notifyListeners: notifyListeners
  1047. };
  1048. };
  1049. var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
  1050. var addEventListener = function addEventListener(node, event, listener) {
  1051. return node.addEventListener ? node.addEventListener(event, listener, false) : node.attachEvent('on' + event, listener);
  1052. };
  1053. var removeEventListener = function removeEventListener(node, event, listener) {
  1054. return node.removeEventListener ? node.removeEventListener(event, listener, false) : node.detachEvent('on' + event, listener);
  1055. };
  1056. var getConfirmation = function getConfirmation(message, callback) {
  1057. return callback(window.confirm(message));
  1058. }; // eslint-disable-line no-alert
  1059. /**
  1060. * Returns true if the HTML5 history API is supported. Taken from Modernizr.
  1061. *
  1062. * https://github.com/Modernizr/Modernizr/blob/master/LICENSE
  1063. * https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
  1064. * changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586
  1065. */
  1066. var supportsHistory = function supportsHistory() {
  1067. var ua = window.navigator.userAgent;
  1068. if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) return false;
  1069. return window.history && 'pushState' in window.history;
  1070. };
  1071. /**
  1072. * Returns true if browser fires popstate on hash change.
  1073. * IE10 and IE11 do not.
  1074. */
  1075. var supportsPopStateOnHashChange = function supportsPopStateOnHashChange() {
  1076. return window.navigator.userAgent.indexOf('Trident') === -1;
  1077. };
  1078. /**
  1079. * Returns false if using go(n) with hash history causes a full page reload.
  1080. */
  1081. var supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() {
  1082. return window.navigator.userAgent.indexOf('Firefox') === -1;
  1083. };
  1084. /**
  1085. * Returns true if a given popstate event is an extraneous WebKit event.
  1086. * Accounts for the fact that Chrome on iOS fires real popstate events
  1087. * containing undefined state when pressing the back button.
  1088. */
  1089. var isExtraneousPopstateEvent = function isExtraneousPopstateEvent(event) {
  1090. return event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1;
  1091. };
  1092. var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  1093. return typeof obj;
  1094. } : function (obj) {
  1095. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  1096. };
  1097. var _extends$1 = Object.assign || function (target) {
  1098. for (var i = 1; i < arguments.length; i++) {
  1099. var source = arguments[i];for (var key in source) {
  1100. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1101. target[key] = source[key];
  1102. }
  1103. }
  1104. }return target;
  1105. };
  1106. var PopStateEvent = 'popstate';
  1107. var HashChangeEvent = 'hashchange';
  1108. var getHistoryState = function getHistoryState() {
  1109. try {
  1110. return window.history.state || {};
  1111. } catch (e) {
  1112. // IE 11 sometimes throws when accessing window.history.state
  1113. // See https://github.com/ReactTraining/history/pull/289
  1114. return {};
  1115. }
  1116. };
  1117. /**
  1118. * Creates a history object that uses the HTML5 history API including
  1119. * pushState, replaceState, and the popstate event.
  1120. */
  1121. var createBrowserHistory = function createBrowserHistory() {
  1122. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1123. invariant_1$1(canUseDOM, 'Browser history needs a DOM');
  1124. var globalHistory = window.history;
  1125. var canUseHistory = supportsHistory();
  1126. var needsHashChangeListener = !supportsPopStateOnHashChange();
  1127. var _props$forceRefresh = props.forceRefresh,
  1128. forceRefresh = _props$forceRefresh === undefined ? false : _props$forceRefresh,
  1129. _props$getUserConfirm = props.getUserConfirmation,
  1130. getUserConfirmation = _props$getUserConfirm === undefined ? getConfirmation : _props$getUserConfirm,
  1131. _props$keyLength = props.keyLength,
  1132. keyLength = _props$keyLength === undefined ? 6 : _props$keyLength;
  1133. var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '';
  1134. var getDOMLocation = function getDOMLocation(historyState) {
  1135. var _ref = historyState || {},
  1136. key = _ref.key,
  1137. state = _ref.state;
  1138. var _window$location = window.location,
  1139. pathname = _window$location.pathname,
  1140. search = _window$location.search,
  1141. hash = _window$location.hash;
  1142. var path = pathname + search + hash;
  1143. warning_1(!basename || hasBasename(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".');
  1144. if (basename) path = stripBasename(path, basename);
  1145. return createLocation(path, state, key);
  1146. };
  1147. var createKey = function createKey() {
  1148. return Math.random().toString(36).substr(2, keyLength);
  1149. };
  1150. var transitionManager = createTransitionManager();
  1151. var setState = function setState(nextState) {
  1152. _extends$1(history, nextState);
  1153. history.length = globalHistory.length;
  1154. transitionManager.notifyListeners(history.location, history.action);
  1155. };
  1156. var handlePopState = function handlePopState(event) {
  1157. // Ignore extraneous popstate events in WebKit.
  1158. if (isExtraneousPopstateEvent(event)) return;
  1159. handlePop(getDOMLocation(event.state));
  1160. };
  1161. var handleHashChange = function handleHashChange() {
  1162. handlePop(getDOMLocation(getHistoryState()));
  1163. };
  1164. var forceNextPop = false;
  1165. var handlePop = function handlePop(location) {
  1166. if (forceNextPop) {
  1167. forceNextPop = false;
  1168. setState();
  1169. } else {
  1170. var action = 'POP';
  1171. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1172. if (ok) {
  1173. setState({ action: action, location: location });
  1174. } else {
  1175. revertPop(location);
  1176. }
  1177. });
  1178. }
  1179. };
  1180. var revertPop = function revertPop(fromLocation) {
  1181. var toLocation = history.location;
  1182. // TODO: We could probably make this more reliable by
  1183. // keeping a list of keys we've seen in sessionStorage.
  1184. // Instead, we just default to 0 for keys we don't know.
  1185. var toIndex = allKeys.indexOf(toLocation.key);
  1186. if (toIndex === -1) toIndex = 0;
  1187. var fromIndex = allKeys.indexOf(fromLocation.key);
  1188. if (fromIndex === -1) fromIndex = 0;
  1189. var delta = toIndex - fromIndex;
  1190. if (delta) {
  1191. forceNextPop = true;
  1192. go(delta);
  1193. }
  1194. };
  1195. var initialLocation = getDOMLocation(getHistoryState());
  1196. var allKeys = [initialLocation.key];
  1197. // Public interface
  1198. var createHref = function createHref(location) {
  1199. return basename + createPath(location);
  1200. };
  1201. var push = function push(path, state) {
  1202. warning_1(!((typeof path === 'undefined' ? 'undefined' : _typeof$1(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored');
  1203. var action = 'PUSH';
  1204. var location = createLocation(path, state, createKey(), history.location);
  1205. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1206. if (!ok) return;
  1207. var href = createHref(location);
  1208. var key = location.key,
  1209. state = location.state;
  1210. if (canUseHistory) {
  1211. globalHistory.pushState({ key: key, state: state }, null, href);
  1212. if (forceRefresh) {
  1213. window.location.href = href;
  1214. } else {
  1215. var prevIndex = allKeys.indexOf(history.location.key);
  1216. var nextKeys = allKeys.slice(0, prevIndex === -1 ? 0 : prevIndex + 1);
  1217. nextKeys.push(location.key);
  1218. allKeys = nextKeys;
  1219. setState({ action: action, location: location });
  1220. }
  1221. } else {
  1222. warning_1(state === undefined, 'Browser history cannot push state in browsers that do not support HTML5 history');
  1223. window.location.href = href;
  1224. }
  1225. });
  1226. };
  1227. var replace = function replace(path, state) {
  1228. warning_1(!((typeof path === 'undefined' ? 'undefined' : _typeof$1(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored');
  1229. var action = 'REPLACE';
  1230. var location = createLocation(path, state, createKey(), history.location);
  1231. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1232. if (!ok) return;
  1233. var href = createHref(location);
  1234. var key = location.key,
  1235. state = location.state;
  1236. if (canUseHistory) {
  1237. globalHistory.replaceState({ key: key, state: state }, null, href);
  1238. if (forceRefresh) {
  1239. window.location.replace(href);
  1240. } else {
  1241. var prevIndex = allKeys.indexOf(history.location.key);
  1242. if (prevIndex !== -1) allKeys[prevIndex] = location.key;
  1243. setState({ action: action, location: location });
  1244. }
  1245. } else {
  1246. warning_1(state === undefined, 'Browser history cannot replace state in browsers that do not support HTML5 history');
  1247. window.location.replace(href);
  1248. }
  1249. });
  1250. };
  1251. var go = function go(n) {
  1252. globalHistory.go(n);
  1253. };
  1254. var goBack = function goBack() {
  1255. return go(-1);
  1256. };
  1257. var goForward = function goForward() {
  1258. return go(1);
  1259. };
  1260. var listenerCount = 0;
  1261. var checkDOMListeners = function checkDOMListeners(delta) {
  1262. listenerCount += delta;
  1263. if (listenerCount === 1) {
  1264. addEventListener(window, PopStateEvent, handlePopState);
  1265. if (needsHashChangeListener) addEventListener(window, HashChangeEvent, handleHashChange);
  1266. } else if (listenerCount === 0) {
  1267. removeEventListener(window, PopStateEvent, handlePopState);
  1268. if (needsHashChangeListener) removeEventListener(window, HashChangeEvent, handleHashChange);
  1269. }
  1270. };
  1271. var isBlocked = false;
  1272. var block = function block() {
  1273. var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1274. var unblock = transitionManager.setPrompt(prompt);
  1275. if (!isBlocked) {
  1276. checkDOMListeners(1);
  1277. isBlocked = true;
  1278. }
  1279. return function () {
  1280. if (isBlocked) {
  1281. isBlocked = false;
  1282. checkDOMListeners(-1);
  1283. }
  1284. return unblock();
  1285. };
  1286. };
  1287. var listen = function listen(listener) {
  1288. var unlisten = transitionManager.appendListener(listener);
  1289. checkDOMListeners(1);
  1290. return function () {
  1291. checkDOMListeners(-1);
  1292. unlisten();
  1293. };
  1294. };
  1295. var history = {
  1296. length: globalHistory.length,
  1297. action: 'POP',
  1298. location: initialLocation,
  1299. createHref: createHref,
  1300. push: push,
  1301. replace: replace,
  1302. go: go,
  1303. goBack: goBack,
  1304. goForward: goForward,
  1305. block: block,
  1306. listen: listen
  1307. };
  1308. return history;
  1309. };
  1310. var _extends$2 = Object.assign || function (target) {
  1311. for (var i = 1; i < arguments.length; i++) {
  1312. var source = arguments[i];for (var key in source) {
  1313. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1314. target[key] = source[key];
  1315. }
  1316. }
  1317. }return target;
  1318. };
  1319. var HashChangeEvent$1 = 'hashchange';
  1320. var HashPathCoders = {
  1321. hashbang: {
  1322. encodePath: function encodePath(path) {
  1323. return path.charAt(0) === '!' ? path : '!/' + stripLeadingSlash(path);
  1324. },
  1325. decodePath: function decodePath(path) {
  1326. return path.charAt(0) === '!' ? path.substr(1) : path;
  1327. }
  1328. },
  1329. noslash: {
  1330. encodePath: stripLeadingSlash,
  1331. decodePath: addLeadingSlash
  1332. },
  1333. slash: {
  1334. encodePath: addLeadingSlash,
  1335. decodePath: addLeadingSlash
  1336. }
  1337. };
  1338. var getHashPath = function getHashPath() {
  1339. // We can't use window.location.hash here because it's not
  1340. // consistent across browsers - Firefox will pre-decode it!
  1341. var href = window.location.href;
  1342. var hashIndex = href.indexOf('#');
  1343. return hashIndex === -1 ? '' : href.substring(hashIndex + 1);
  1344. };
  1345. var pushHashPath = function pushHashPath(path) {
  1346. return window.location.hash = path;
  1347. };
  1348. var replaceHashPath = function replaceHashPath(path) {
  1349. var hashIndex = window.location.href.indexOf('#');
  1350. window.location.replace(window.location.href.slice(0, hashIndex >= 0 ? hashIndex : 0) + '#' + path);
  1351. };
  1352. var createHashHistory = function createHashHistory() {
  1353. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1354. invariant_1$1(canUseDOM, 'Hash history needs a DOM');
  1355. var globalHistory = window.history;
  1356. var canGoWithoutReload = supportsGoWithoutReloadUsingHash();
  1357. var _props$getUserConfirm = props.getUserConfirmation,
  1358. getUserConfirmation = _props$getUserConfirm === undefined ? getConfirmation : _props$getUserConfirm,
  1359. _props$hashType = props.hashType,
  1360. hashType = _props$hashType === undefined ? 'slash' : _props$hashType;
  1361. var basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '';
  1362. var _HashPathCoders$hashT = HashPathCoders[hashType],
  1363. encodePath = _HashPathCoders$hashT.encodePath,
  1364. decodePath = _HashPathCoders$hashT.decodePath;
  1365. var getDOMLocation = function getDOMLocation() {
  1366. var path = decodePath(getHashPath());
  1367. warning_1(!basename || hasBasename(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".');
  1368. if (basename) path = stripBasename(path, basename);
  1369. return createLocation(path);
  1370. };
  1371. var transitionManager = createTransitionManager();
  1372. var setState = function setState(nextState) {
  1373. _extends$2(history, nextState);
  1374. history.length = globalHistory.length;
  1375. transitionManager.notifyListeners(history.location, history.action);
  1376. };
  1377. var forceNextPop = false;
  1378. var ignorePath = null;
  1379. var handleHashChange = function handleHashChange() {
  1380. var path = getHashPath();
  1381. var encodedPath = encodePath(path);
  1382. if (path !== encodedPath) {
  1383. // Ensure we always have a properly-encoded hash.
  1384. replaceHashPath(encodedPath);
  1385. } else {
  1386. var location = getDOMLocation();
  1387. var prevLocation = history.location;
  1388. if (!forceNextPop && locationsAreEqual(prevLocation, location)) return; // A hashchange doesn't always == location change.
  1389. if (ignorePath === createPath(location)) return; // Ignore this change; we already setState in push/replace.
  1390. ignorePath = null;
  1391. handlePop(location);
  1392. }
  1393. };
  1394. var handlePop = function handlePop(location) {
  1395. if (forceNextPop) {
  1396. forceNextPop = false;
  1397. setState();
  1398. } else {
  1399. var action = 'POP';
  1400. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1401. if (ok) {
  1402. setState({ action: action, location: location });
  1403. } else {
  1404. revertPop(location);
  1405. }
  1406. });
  1407. }
  1408. };
  1409. var revertPop = function revertPop(fromLocation) {
  1410. var toLocation = history.location;
  1411. // TODO: We could probably make this more reliable by
  1412. // keeping a list of paths we've seen in sessionStorage.
  1413. // Instead, we just default to 0 for paths we don't know.
  1414. var toIndex = allPaths.lastIndexOf(createPath(toLocation));
  1415. if (toIndex === -1) toIndex = 0;
  1416. var fromIndex = allPaths.lastIndexOf(createPath(fromLocation));
  1417. if (fromIndex === -1) fromIndex = 0;
  1418. var delta = toIndex - fromIndex;
  1419. if (delta) {
  1420. forceNextPop = true;
  1421. go(delta);
  1422. }
  1423. };
  1424. // Ensure the hash is encoded properly before doing anything else.
  1425. var path = getHashPath();
  1426. var encodedPath = encodePath(path);
  1427. if (path !== encodedPath) replaceHashPath(encodedPath);
  1428. var initialLocation = getDOMLocation();
  1429. var allPaths = [createPath(initialLocation)];
  1430. // Public interface
  1431. var createHref = function createHref(location) {
  1432. return '#' + encodePath(basename + createPath(location));
  1433. };
  1434. var push = function push(path, state) {
  1435. warning_1(state === undefined, 'Hash history cannot push state; it is ignored');
  1436. var action = 'PUSH';
  1437. var location = createLocation(path, undefined, undefined, history.location);
  1438. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1439. if (!ok) return;
  1440. var path = createPath(location);
  1441. var encodedPath = encodePath(basename + path);
  1442. var hashChanged = getHashPath() !== encodedPath;
  1443. if (hashChanged) {
  1444. // We cannot tell if a hashchange was caused by a PUSH, so we'd
  1445. // rather setState here and ignore the hashchange. The caveat here
  1446. // is that other hash histories in the page will consider it a POP.
  1447. ignorePath = path;
  1448. pushHashPath(encodedPath);
  1449. var prevIndex = allPaths.lastIndexOf(createPath(history.location));
  1450. var nextPaths = allPaths.slice(0, prevIndex === -1 ? 0 : prevIndex + 1);
  1451. nextPaths.push(path);
  1452. allPaths = nextPaths;
  1453. setState({ action: action, location: location });
  1454. } else {
  1455. warning_1(false, 'Hash history cannot PUSH the same path; a new entry will not be added to the history stack');
  1456. setState();
  1457. }
  1458. });
  1459. };
  1460. var replace = function replace(path, state) {
  1461. warning_1(state === undefined, 'Hash history cannot replace state; it is ignored');
  1462. var action = 'REPLACE';
  1463. var location = createLocation(path, undefined, undefined, history.location);
  1464. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1465. if (!ok) return;
  1466. var path = createPath(location);
  1467. var encodedPath = encodePath(basename + path);
  1468. var hashChanged = getHashPath() !== encodedPath;
  1469. if (hashChanged) {
  1470. // We cannot tell if a hashchange was caused by a REPLACE, so we'd
  1471. // rather setState here and ignore the hashchange. The caveat here
  1472. // is that other hash histories in the page will consider it a POP.
  1473. ignorePath = path;
  1474. replaceHashPath(encodedPath);
  1475. }
  1476. var prevIndex = allPaths.indexOf(createPath(history.location));
  1477. if (prevIndex !== -1) allPaths[prevIndex] = path;
  1478. setState({ action: action, location: location });
  1479. });
  1480. };
  1481. var go = function go(n) {
  1482. warning_1(canGoWithoutReload, 'Hash history go(n) causes a full page reload in this browser');
  1483. globalHistory.go(n);
  1484. };
  1485. var goBack = function goBack() {
  1486. return go(-1);
  1487. };
  1488. var goForward = function goForward() {
  1489. return go(1);
  1490. };
  1491. var listenerCount = 0;
  1492. var checkDOMListeners = function checkDOMListeners(delta) {
  1493. listenerCount += delta;
  1494. if (listenerCount === 1) {
  1495. addEventListener(window, HashChangeEvent$1, handleHashChange);
  1496. } else if (listenerCount === 0) {
  1497. removeEventListener(window, HashChangeEvent$1, handleHashChange);
  1498. }
  1499. };
  1500. var isBlocked = false;
  1501. var block = function block() {
  1502. var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1503. var unblock = transitionManager.setPrompt(prompt);
  1504. if (!isBlocked) {
  1505. checkDOMListeners(1);
  1506. isBlocked = true;
  1507. }
  1508. return function () {
  1509. if (isBlocked) {
  1510. isBlocked = false;
  1511. checkDOMListeners(-1);
  1512. }
  1513. return unblock();
  1514. };
  1515. };
  1516. var listen = function listen(listener) {
  1517. var unlisten = transitionManager.appendListener(listener);
  1518. checkDOMListeners(1);
  1519. return function () {
  1520. checkDOMListeners(-1);
  1521. unlisten();
  1522. };
  1523. };
  1524. var history = {
  1525. length: globalHistory.length,
  1526. action: 'POP',
  1527. location: initialLocation,
  1528. createHref: createHref,
  1529. push: push,
  1530. replace: replace,
  1531. go: go,
  1532. goBack: goBack,
  1533. goForward: goForward,
  1534. block: block,
  1535. listen: listen
  1536. };
  1537. return history;
  1538. };
  1539. var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  1540. return typeof obj;
  1541. } : function (obj) {
  1542. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  1543. };
  1544. var _extends$3 = Object.assign || function (target) {
  1545. for (var i = 1; i < arguments.length; i++) {
  1546. var source = arguments[i];for (var key in source) {
  1547. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1548. target[key] = source[key];
  1549. }
  1550. }
  1551. }return target;
  1552. };
  1553. var clamp = function clamp(n, lowerBound, upperBound) {
  1554. return Math.min(Math.max(n, lowerBound), upperBound);
  1555. };
  1556. /**
  1557. * Creates a history object that stores locations in memory.
  1558. */
  1559. var createMemoryHistory = function createMemoryHistory() {
  1560. var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1561. var getUserConfirmation = props.getUserConfirmation,
  1562. _props$initialEntries = props.initialEntries,
  1563. initialEntries = _props$initialEntries === undefined ? ['/'] : _props$initialEntries,
  1564. _props$initialIndex = props.initialIndex,
  1565. initialIndex = _props$initialIndex === undefined ? 0 : _props$initialIndex,
  1566. _props$keyLength = props.keyLength,
  1567. keyLength = _props$keyLength === undefined ? 6 : _props$keyLength;
  1568. var transitionManager = createTransitionManager();
  1569. var setState = function setState(nextState) {
  1570. _extends$3(history, nextState);
  1571. history.length = history.entries.length;
  1572. transitionManager.notifyListeners(history.location, history.action);
  1573. };
  1574. var createKey = function createKey() {
  1575. return Math.random().toString(36).substr(2, keyLength);
  1576. };
  1577. var index = clamp(initialIndex, 0, initialEntries.length - 1);
  1578. var entries = initialEntries.map(function (entry) {
  1579. return typeof entry === 'string' ? createLocation(entry, undefined, createKey()) : createLocation(entry, undefined, entry.key || createKey());
  1580. });
  1581. // Public interface
  1582. var createHref = createPath;
  1583. var push = function push(path, state) {
  1584. warning_1(!((typeof path === 'undefined' ? 'undefined' : _typeof$2(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to push when the 1st ' + 'argument is a location-like object that already has state; it is ignored');
  1585. var action = 'PUSH';
  1586. var location = createLocation(path, state, createKey(), history.location);
  1587. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1588. if (!ok) return;
  1589. var prevIndex = history.index;
  1590. var nextIndex = prevIndex + 1;
  1591. var nextEntries = history.entries.slice(0);
  1592. if (nextEntries.length > nextIndex) {
  1593. nextEntries.splice(nextIndex, nextEntries.length - nextIndex, location);
  1594. } else {
  1595. nextEntries.push(location);
  1596. }
  1597. setState({
  1598. action: action,
  1599. location: location,
  1600. index: nextIndex,
  1601. entries: nextEntries
  1602. });
  1603. });
  1604. };
  1605. var replace = function replace(path, state) {
  1606. warning_1(!((typeof path === 'undefined' ? 'undefined' : _typeof$2(path)) === 'object' && path.state !== undefined && state !== undefined), 'You should avoid providing a 2nd state argument to replace when the 1st ' + 'argument is a location-like object that already has state; it is ignored');
  1607. var action = 'REPLACE';
  1608. var location = createLocation(path, state, createKey(), history.location);
  1609. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1610. if (!ok) return;
  1611. history.entries[history.index] = location;
  1612. setState({ action: action, location: location });
  1613. });
  1614. };
  1615. var go = function go(n) {
  1616. var nextIndex = clamp(history.index + n, 0, history.entries.length - 1);
  1617. var action = 'POP';
  1618. var location = history.entries[nextIndex];
  1619. transitionManager.confirmTransitionTo(location, action, getUserConfirmation, function (ok) {
  1620. if (ok) {
  1621. setState({
  1622. action: action,
  1623. location: location,
  1624. index: nextIndex
  1625. });
  1626. } else {
  1627. // Mimic the behavior of DOM histories by
  1628. // causing a render after a cancelled POP.
  1629. setState();
  1630. }
  1631. });
  1632. };
  1633. var goBack = function goBack() {
  1634. return go(-1);
  1635. };
  1636. var goForward = function goForward() {
  1637. return go(1);
  1638. };
  1639. var canGo = function canGo(n) {
  1640. var nextIndex = history.index + n;
  1641. return nextIndex >= 0 && nextIndex < history.entries.length;
  1642. };
  1643. var block = function block() {
  1644. var prompt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1645. return transitionManager.setPrompt(prompt);
  1646. };
  1647. var listen = function listen(listener) {
  1648. return transitionManager.appendListener(listener);
  1649. };
  1650. var history = {
  1651. length: entries.length,
  1652. action: 'POP',
  1653. location: entries[index],
  1654. index: index,
  1655. entries: entries,
  1656. createHref: createHref,
  1657. push: push,
  1658. replace: replace,
  1659. go: go,
  1660. goBack: goBack,
  1661. goForward: goForward,
  1662. canGo: canGo,
  1663. block: block,
  1664. listen: listen
  1665. };
  1666. return history;
  1667. };
  1668. var _extends$4 = Object.assign || function (target) {
  1669. for (var i = 1; i < arguments.length; i++) {
  1670. var source = arguments[i];for (var key in source) {
  1671. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1672. target[key] = source[key];
  1673. }
  1674. }
  1675. }return target;
  1676. };
  1677. function _classCallCheck(instance, Constructor) {
  1678. if (!(instance instanceof Constructor)) {
  1679. throw new TypeError("Cannot call a class as a function");
  1680. }
  1681. }
  1682. function _possibleConstructorReturn(self, call) {
  1683. if (!self) {
  1684. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1685. }return call && (typeof call === "object" || typeof call === "function") ? call : self;
  1686. }
  1687. function _inherits(subClass, superClass) {
  1688. if (typeof superClass !== "function" && superClass !== null) {
  1689. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  1690. }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  1691. }
  1692. /**
  1693. * The public API for putting history on context.
  1694. */
  1695. var Router = function (_React$Component) {
  1696. _inherits(Router, _React$Component);
  1697. function Router() {
  1698. var _temp, _this, _ret;
  1699. _classCallCheck(this, Router);
  1700. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1701. args[_key] = arguments[_key];
  1702. }
  1703. return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  1704. match: _this.computeMatch(_this.props.history.location.pathname)
  1705. }, _temp), _possibleConstructorReturn(_this, _ret);
  1706. }
  1707. Router.prototype.getChildContext = function getChildContext() {
  1708. return {
  1709. router: _extends$4({}, this.context.router, {
  1710. history: this.props.history,
  1711. route: {
  1712. location: this.props.history.location,
  1713. match: this.state.match
  1714. }
  1715. })
  1716. };
  1717. };
  1718. Router.prototype.computeMatch = function computeMatch(pathname) {
  1719. return {
  1720. path: "/",
  1721. url: "/",
  1722. params: {},
  1723. isExact: pathname === "/"
  1724. };
  1725. };
  1726. Router.prototype.componentWillMount = function componentWillMount() {
  1727. var _this2 = this;
  1728. var _props = this.props,
  1729. children = _props.children,
  1730. history = _props.history;
  1731. invariant_1$1(children == null || React.Children.count(children) === 1, "A <Router> may have only one child element");
  1732. // Do this here so we can setState when a <Redirect> changes the
  1733. // location in componentWillMount. This happens e.g. when doing
  1734. // server rendering using a <StaticRouter>.
  1735. this.unlisten = history.listen(function () {
  1736. _this2.setState({
  1737. match: _this2.computeMatch(history.location.pathname)
  1738. });
  1739. });
  1740. };
  1741. Router.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  1742. warning_1(this.props.history === nextProps.history, "You cannot change <Router history>");
  1743. };
  1744. Router.prototype.componentWillUnmount = function componentWillUnmount() {
  1745. this.unlisten();
  1746. };
  1747. Router.prototype.render = function render() {
  1748. var children = this.props.children;
  1749. return children ? React.Children.only(children) : null;
  1750. };
  1751. return Router;
  1752. }(React.Component);
  1753. Router.propTypes = {
  1754. history: propTypes.object.isRequired,
  1755. children: propTypes.node
  1756. };
  1757. Router.contextTypes = {
  1758. router: propTypes.object
  1759. };
  1760. Router.childContextTypes = {
  1761. router: propTypes.object.isRequired
  1762. };
  1763. // Written in this round about way for babel-transform-imports
  1764. var _typeof$3 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  1765. return typeof obj;
  1766. } : function (obj) {
  1767. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  1768. };
  1769. var classCallCheck = function (instance, Constructor) {
  1770. if (!(instance instanceof Constructor)) {
  1771. throw new TypeError("Cannot call a class as a function");
  1772. }
  1773. };
  1774. var _extends$5 = Object.assign || function (target) {
  1775. for (var i = 1; i < arguments.length; i++) {
  1776. var source = arguments[i];
  1777. for (var key in source) {
  1778. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1779. target[key] = source[key];
  1780. }
  1781. }
  1782. }
  1783. return target;
  1784. };
  1785. var inherits = function (subClass, superClass) {
  1786. if (typeof superClass !== "function" && superClass !== null) {
  1787. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  1788. }
  1789. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1790. constructor: {
  1791. value: subClass,
  1792. enumerable: false,
  1793. writable: true,
  1794. configurable: true
  1795. }
  1796. });
  1797. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  1798. };
  1799. var objectWithoutProperties = function (obj, keys) {
  1800. var target = {};
  1801. for (var i in obj) {
  1802. if (keys.indexOf(i) >= 0) continue;
  1803. if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
  1804. target[i] = obj[i];
  1805. }
  1806. return target;
  1807. };
  1808. var possibleConstructorReturn = function (self, call) {
  1809. if (!self) {
  1810. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1811. }
  1812. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  1813. };
  1814. /**
  1815. * The public API for a <Router> that uses HTML5 history.
  1816. */
  1817. var BrowserRouter = function (_React$Component) {
  1818. inherits(BrowserRouter, _React$Component);
  1819. function BrowserRouter() {
  1820. var _temp, _this, _ret;
  1821. classCallCheck(this, BrowserRouter);
  1822. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1823. args[_key] = arguments[_key];
  1824. }
  1825. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.history = createBrowserHistory(_this.props), _temp), possibleConstructorReturn(_this, _ret);
  1826. }
  1827. BrowserRouter.prototype.componentWillMount = function componentWillMount() {
  1828. warning_1(!this.props.history, "<BrowserRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { BrowserRouter as Router }`.");
  1829. };
  1830. BrowserRouter.prototype.render = function render() {
  1831. return React.createElement(Router, { history: this.history, children: this.props.children });
  1832. };
  1833. return BrowserRouter;
  1834. }(React.Component);
  1835. BrowserRouter.propTypes = {
  1836. basename: propTypes.string,
  1837. forceRefresh: propTypes.bool,
  1838. getUserConfirmation: propTypes.func,
  1839. keyLength: propTypes.number,
  1840. children: propTypes.node
  1841. };
  1842. /**
  1843. * The public API for a <Router> that uses window.location.hash.
  1844. */
  1845. var HashRouter = function (_React$Component) {
  1846. inherits(HashRouter, _React$Component);
  1847. function HashRouter() {
  1848. var _temp, _this, _ret;
  1849. classCallCheck(this, HashRouter);
  1850. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1851. args[_key] = arguments[_key];
  1852. }
  1853. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.history = createHashHistory(_this.props), _temp), possibleConstructorReturn(_this, _ret);
  1854. }
  1855. HashRouter.prototype.componentWillMount = function componentWillMount() {
  1856. warning_1(!this.props.history, "<HashRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { HashRouter as Router }`.");
  1857. };
  1858. HashRouter.prototype.render = function render() {
  1859. return React.createElement(Router, { history: this.history, children: this.props.children });
  1860. };
  1861. return HashRouter;
  1862. }(React.Component);
  1863. HashRouter.propTypes = {
  1864. basename: propTypes.string,
  1865. getUserConfirmation: propTypes.func,
  1866. hashType: propTypes.oneOf(["hashbang", "noslash", "slash"]),
  1867. children: propTypes.node
  1868. };
  1869. var isModifiedEvent = function isModifiedEvent(event) {
  1870. return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
  1871. };
  1872. /**
  1873. * The public API for rendering a history-aware <a>.
  1874. */
  1875. var Link = function (_React$Component) {
  1876. inherits(Link, _React$Component);
  1877. function Link() {
  1878. var _temp, _this, _ret;
  1879. classCallCheck(this, Link);
  1880. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1881. args[_key] = arguments[_key];
  1882. }
  1883. return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.handleClick = function (event) {
  1884. if (_this.props.onClick) _this.props.onClick(event);
  1885. if (!event.defaultPrevented && // onClick prevented default
  1886. event.button === 0 && // ignore everything but left clicks
  1887. !_this.props.target && // let browser handle "target=_blank" etc.
  1888. !isModifiedEvent(event) // ignore clicks with modifier keys
  1889. ) {
  1890. event.preventDefault();
  1891. var history = _this.context.router.history;
  1892. var _this$props = _this.props,
  1893. replace = _this$props.replace,
  1894. to = _this$props.to;
  1895. if (replace) {
  1896. history.replace(to);
  1897. } else {
  1898. history.push(to);
  1899. }
  1900. }
  1901. }, _temp), possibleConstructorReturn(_this, _ret);
  1902. }
  1903. Link.prototype.render = function render() {
  1904. var _props = this.props,
  1905. replace = _props.replace,
  1906. to = _props.to,
  1907. innerRef = _props.innerRef,
  1908. props = objectWithoutProperties(_props, ["replace", "to", "innerRef"]); // eslint-disable-line no-unused-vars
  1909. invariant_1$1(this.context.router, "You should not use <Link> outside a <Router>");
  1910. invariant_1$1(to !== undefined, 'You must specify the "to" property');
  1911. var history = this.context.router.history;
  1912. var location = typeof to === "string" ? createLocation(to, null, null, history.location) : to;
  1913. var href = history.createHref(location);
  1914. return React.createElement("a", _extends$5({}, props, { onClick: this.handleClick, href: href, ref: innerRef }));
  1915. };
  1916. return Link;
  1917. }(React.Component);
  1918. Link.propTypes = {
  1919. onClick: propTypes.func,
  1920. target: propTypes.string,
  1921. replace: propTypes.bool,
  1922. to: propTypes.oneOfType([propTypes.string, propTypes.object]).isRequired,
  1923. innerRef: propTypes.oneOfType([propTypes.string, propTypes.func])
  1924. };
  1925. Link.defaultProps = {
  1926. replace: false
  1927. };
  1928. Link.contextTypes = {
  1929. router: propTypes.shape({
  1930. history: propTypes.shape({
  1931. push: propTypes.func.isRequired,
  1932. replace: propTypes.func.isRequired,
  1933. createHref: propTypes.func.isRequired
  1934. }).isRequired
  1935. }).isRequired
  1936. };
  1937. function _classCallCheck$1(instance, Constructor) {
  1938. if (!(instance instanceof Constructor)) {
  1939. throw new TypeError("Cannot call a class as a function");
  1940. }
  1941. }
  1942. function _possibleConstructorReturn$1(self, call) {
  1943. if (!self) {
  1944. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1945. }return call && (typeof call === "object" || typeof call === "function") ? call : self;
  1946. }
  1947. function _inherits$1(subClass, superClass) {
  1948. if (typeof superClass !== "function" && superClass !== null) {
  1949. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  1950. }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  1951. }
  1952. /**
  1953. * The public API for a <Router> that stores location in memory.
  1954. */
  1955. var MemoryRouter = function (_React$Component) {
  1956. _inherits$1(MemoryRouter, _React$Component);
  1957. function MemoryRouter() {
  1958. var _temp, _this, _ret;
  1959. _classCallCheck$1(this, MemoryRouter);
  1960. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  1961. args[_key] = arguments[_key];
  1962. }
  1963. return _ret = (_temp = (_this = _possibleConstructorReturn$1(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.history = createMemoryHistory(_this.props), _temp), _possibleConstructorReturn$1(_this, _ret);
  1964. }
  1965. MemoryRouter.prototype.componentWillMount = function componentWillMount() {
  1966. warning_1(!this.props.history, "<MemoryRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { MemoryRouter as Router }`.");
  1967. };
  1968. MemoryRouter.prototype.render = function render() {
  1969. return React.createElement(Router, { history: this.history, children: this.props.children });
  1970. };
  1971. return MemoryRouter;
  1972. }(React.Component);
  1973. MemoryRouter.propTypes = {
  1974. initialEntries: propTypes.array,
  1975. initialIndex: propTypes.number,
  1976. getUserConfirmation: propTypes.func,
  1977. keyLength: propTypes.number,
  1978. children: propTypes.node
  1979. };
  1980. // Written in this round about way for babel-transform-imports
  1981. var toString = {}.toString;
  1982. var isarray = Array.isArray || function (arr) {
  1983. return toString.call(arr) == '[object Array]';
  1984. };
  1985. /**
  1986. * Expose `pathToRegexp`.
  1987. */
  1988. var pathToRegexp_1 = pathToRegexp;
  1989. var parse_1 = parse;
  1990. var compile_1 = compile;
  1991. var tokensToFunction_1 = tokensToFunction;
  1992. var tokensToRegExp_1 = tokensToRegExp;
  1993. /**
  1994. * The main path matching regexp utility.
  1995. *
  1996. * @type {RegExp}
  1997. */
  1998. var PATH_REGEXP = new RegExp([
  1999. // Match escaped characters that would otherwise appear in future matches.
  2000. // This allows the user to escape special characters that won't transform.
  2001. '(\\\\.)',
  2002. // Match Express-style parameters and un-named parameters with a prefix
  2003. // and optional suffixes. Matches appear as:
  2004. //
  2005. // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
  2006. // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
  2007. // "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
  2008. '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'].join('|'), 'g');
  2009. /**
  2010. * Parse a string for the raw tokens.
  2011. *
  2012. * @param {string} str
  2013. * @param {Object=} options
  2014. * @return {!Array}
  2015. */
  2016. function parse(str, options) {
  2017. var tokens = [];
  2018. var key = 0;
  2019. var index = 0;
  2020. var path = '';
  2021. var defaultDelimiter = options && options.delimiter || '/';
  2022. var res;
  2023. while ((res = PATH_REGEXP.exec(str)) != null) {
  2024. var m = res[0];
  2025. var escaped = res[1];
  2026. var offset = res.index;
  2027. path += str.slice(index, offset);
  2028. index = offset + m.length;
  2029. // Ignore already escaped sequences.
  2030. if (escaped) {
  2031. path += escaped[1];
  2032. continue;
  2033. }
  2034. var next = str[index];
  2035. var prefix = res[2];
  2036. var name = res[3];
  2037. var capture = res[4];
  2038. var group = res[5];
  2039. var modifier = res[6];
  2040. var asterisk = res[7];
  2041. // Push the current path onto the tokens.
  2042. if (path) {
  2043. tokens.push(path);
  2044. path = '';
  2045. }
  2046. var partial = prefix != null && next != null && next !== prefix;
  2047. var repeat = modifier === '+' || modifier === '*';
  2048. var optional = modifier === '?' || modifier === '*';
  2049. var delimiter = res[2] || defaultDelimiter;
  2050. var pattern = capture || group;
  2051. tokens.push({
  2052. name: name || key++,
  2053. prefix: prefix || '',
  2054. delimiter: delimiter,
  2055. optional: optional,
  2056. repeat: repeat,
  2057. partial: partial,
  2058. asterisk: !!asterisk,
  2059. pattern: pattern ? escapeGroup(pattern) : asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?'
  2060. });
  2061. }
  2062. // Match any characters still remaining.
  2063. if (index < str.length) {
  2064. path += str.substr(index);
  2065. }
  2066. // If the path exists, push it onto the end.
  2067. if (path) {
  2068. tokens.push(path);
  2069. }
  2070. return tokens;
  2071. }
  2072. /**
  2073. * Compile a string to a template function for the path.
  2074. *
  2075. * @param {string} str
  2076. * @param {Object=} options
  2077. * @return {!function(Object=, Object=)}
  2078. */
  2079. function compile(str, options) {
  2080. return tokensToFunction(parse(str, options));
  2081. }
  2082. /**
  2083. * Prettier encoding of URI path segments.
  2084. *
  2085. * @param {string}
  2086. * @return {string}
  2087. */
  2088. function encodeURIComponentPretty(str) {
  2089. return encodeURI(str).replace(/[\/?#]/g, function (c) {
  2090. return '%' + c.charCodeAt(0).toString(16).toUpperCase();
  2091. });
  2092. }
  2093. /**
  2094. * Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
  2095. *
  2096. * @param {string}
  2097. * @return {string}
  2098. */
  2099. function encodeAsterisk(str) {
  2100. return encodeURI(str).replace(/[?#]/g, function (c) {
  2101. return '%' + c.charCodeAt(0).toString(16).toUpperCase();
  2102. });
  2103. }
  2104. /**
  2105. * Expose a method for transforming tokens into the path function.
  2106. */
  2107. function tokensToFunction(tokens) {
  2108. // Compile all the tokens into regexps.
  2109. var matches = new Array(tokens.length);
  2110. // Compile all the patterns before compilation.
  2111. for (var i = 0; i < tokens.length; i++) {
  2112. if (typeof tokens[i] === 'object') {
  2113. matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$');
  2114. }
  2115. }
  2116. return function (obj, opts) {
  2117. var path = '';
  2118. var data = obj || {};
  2119. var options = opts || {};
  2120. var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent;
  2121. for (var i = 0; i < tokens.length; i++) {
  2122. var token = tokens[i];
  2123. if (typeof token === 'string') {
  2124. path += token;
  2125. continue;
  2126. }
  2127. var value = data[token.name];
  2128. var segment;
  2129. if (value == null) {
  2130. if (token.optional) {
  2131. // Prepend partial segment prefixes.
  2132. if (token.partial) {
  2133. path += token.prefix;
  2134. }
  2135. continue;
  2136. } else {
  2137. throw new TypeError('Expected "' + token.name + '" to be defined');
  2138. }
  2139. }
  2140. if (isarray(value)) {
  2141. if (!token.repeat) {
  2142. throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`');
  2143. }
  2144. if (value.length === 0) {
  2145. if (token.optional) {
  2146. continue;
  2147. } else {
  2148. throw new TypeError('Expected "' + token.name + '" to not be empty');
  2149. }
  2150. }
  2151. for (var j = 0; j < value.length; j++) {
  2152. segment = encode(value[j]);
  2153. if (!matches[i].test(segment)) {
  2154. throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`');
  2155. }
  2156. path += (j === 0 ? token.prefix : token.delimiter) + segment;
  2157. }
  2158. continue;
  2159. }
  2160. segment = token.asterisk ? encodeAsterisk(value) : encode(value);
  2161. if (!matches[i].test(segment)) {
  2162. throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"');
  2163. }
  2164. path += token.prefix + segment;
  2165. }
  2166. return path;
  2167. };
  2168. }
  2169. /**
  2170. * Escape a regular expression string.
  2171. *
  2172. * @param {string} str
  2173. * @return {string}
  2174. */
  2175. function escapeString(str) {
  2176. return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1');
  2177. }
  2178. /**
  2179. * Escape the capturing group by escaping special characters and meaning.
  2180. *
  2181. * @param {string} group
  2182. * @return {string}
  2183. */
  2184. function escapeGroup(group) {
  2185. return group.replace(/([=!:$\/()])/g, '\\$1');
  2186. }
  2187. /**
  2188. * Attach the keys as a property of the regexp.
  2189. *
  2190. * @param {!RegExp} re
  2191. * @param {Array} keys
  2192. * @return {!RegExp}
  2193. */
  2194. function attachKeys(re, keys) {
  2195. re.keys = keys;
  2196. return re;
  2197. }
  2198. /**
  2199. * Get the flags for a regexp from the options.
  2200. *
  2201. * @param {Object} options
  2202. * @return {string}
  2203. */
  2204. function flags(options) {
  2205. return options.sensitive ? '' : 'i';
  2206. }
  2207. /**
  2208. * Pull out keys from a regexp.
  2209. *
  2210. * @param {!RegExp} path
  2211. * @param {!Array} keys
  2212. * @return {!RegExp}
  2213. */
  2214. function regexpToRegexp(path, keys) {
  2215. // Use a negative lookahead to match only capturing groups.
  2216. var groups = path.source.match(/\((?!\?)/g);
  2217. if (groups) {
  2218. for (var i = 0; i < groups.length; i++) {
  2219. keys.push({
  2220. name: i,
  2221. prefix: null,
  2222. delimiter: null,
  2223. optional: false,
  2224. repeat: false,
  2225. partial: false,
  2226. asterisk: false,
  2227. pattern: null
  2228. });
  2229. }
  2230. }
  2231. return attachKeys(path, keys);
  2232. }
  2233. /**
  2234. * Transform an array into a regexp.
  2235. *
  2236. * @param {!Array} path
  2237. * @param {Array} keys
  2238. * @param {!Object} options
  2239. * @return {!RegExp}
  2240. */
  2241. function arrayToRegexp(path, keys, options) {
  2242. var parts = [];
  2243. for (var i = 0; i < path.length; i++) {
  2244. parts.push(pathToRegexp(path[i], keys, options).source);
  2245. }
  2246. var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options));
  2247. return attachKeys(regexp, keys);
  2248. }
  2249. /**
  2250. * Create a path regexp from string input.
  2251. *
  2252. * @param {string} path
  2253. * @param {!Array} keys
  2254. * @param {!Object} options
  2255. * @return {!RegExp}
  2256. */
  2257. function stringToRegexp(path, keys, options) {
  2258. return tokensToRegExp(parse(path, options), keys, options);
  2259. }
  2260. /**
  2261. * Expose a function for taking tokens and returning a RegExp.
  2262. *
  2263. * @param {!Array} tokens
  2264. * @param {(Array|Object)=} keys
  2265. * @param {Object=} options
  2266. * @return {!RegExp}
  2267. */
  2268. function tokensToRegExp(tokens, keys, options) {
  2269. if (!isarray(keys)) {
  2270. options = /** @type {!Object} */keys || options;
  2271. keys = [];
  2272. }
  2273. options = options || {};
  2274. var strict = options.strict;
  2275. var end = options.end !== false;
  2276. var route = '';
  2277. // Iterate over the tokens and create our regexp string.
  2278. for (var i = 0; i < tokens.length; i++) {
  2279. var token = tokens[i];
  2280. if (typeof token === 'string') {
  2281. route += escapeString(token);
  2282. } else {
  2283. var prefix = escapeString(token.prefix);
  2284. var capture = '(?:' + token.pattern + ')';
  2285. keys.push(token);
  2286. if (token.repeat) {
  2287. capture += '(?:' + prefix + capture + ')*';
  2288. }
  2289. if (token.optional) {
  2290. if (!token.partial) {
  2291. capture = '(?:' + prefix + '(' + capture + '))?';
  2292. } else {
  2293. capture = prefix + '(' + capture + ')?';
  2294. }
  2295. } else {
  2296. capture = prefix + '(' + capture + ')';
  2297. }
  2298. route += capture;
  2299. }
  2300. }
  2301. var delimiter = escapeString(options.delimiter || '/');
  2302. var endsWithDelimiter = route.slice(-delimiter.length) === delimiter;
  2303. // In non-strict mode we allow a slash at the end of match. If the path to
  2304. // match already ends with a slash, we remove it for consistency. The slash
  2305. // is valid at the end of a path match, not in the middle. This is important
  2306. // in non-ending mode, where "/test/" shouldn't match "/test//route".
  2307. if (!strict) {
  2308. route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?';
  2309. }
  2310. if (end) {
  2311. route += '$';
  2312. } else {
  2313. // In non-ending mode, we need the capturing groups to match as much as
  2314. // possible by using a positive lookahead to the end or next path segment.
  2315. route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)';
  2316. }
  2317. return attachKeys(new RegExp('^' + route, flags(options)), keys);
  2318. }
  2319. /**
  2320. * Normalize the given path string, returning a regular expression.
  2321. *
  2322. * An empty array can be passed in for the keys, which will hold the
  2323. * placeholder key descriptions. For example, using `/user/:id`, `keys` will
  2324. * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
  2325. *
  2326. * @param {(string|RegExp|Array)} path
  2327. * @param {(Array|Object)=} keys
  2328. * @param {Object=} options
  2329. * @return {!RegExp}
  2330. */
  2331. function pathToRegexp(path, keys, options) {
  2332. if (!isarray(keys)) {
  2333. options = /** @type {!Object} */keys || options;
  2334. keys = [];
  2335. }
  2336. options = options || {};
  2337. if (path instanceof RegExp) {
  2338. return regexpToRegexp(path, /** @type {!Array} */keys);
  2339. }
  2340. if (isarray(path)) {
  2341. return arrayToRegexp( /** @type {!Array} */path, /** @type {!Array} */keys, options);
  2342. }
  2343. return stringToRegexp( /** @type {string} */path, /** @type {!Array} */keys, options);
  2344. }
  2345. pathToRegexp_1.parse = parse_1;
  2346. pathToRegexp_1.compile = compile_1;
  2347. pathToRegexp_1.tokensToFunction = tokensToFunction_1;
  2348. pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
  2349. var patternCache = {};
  2350. var cacheLimit = 10000;
  2351. var cacheCount = 0;
  2352. var compilePath = function compilePath(pattern, options) {
  2353. var cacheKey = "" + options.end + options.strict + options.sensitive;
  2354. var cache = patternCache[cacheKey] || (patternCache[cacheKey] = {});
  2355. if (cache[pattern]) return cache[pattern];
  2356. var keys = [];
  2357. var re = pathToRegexp_1(pattern, keys, options);
  2358. var compiledPattern = { re: re, keys: keys };
  2359. if (cacheCount < cacheLimit) {
  2360. cache[pattern] = compiledPattern;
  2361. cacheCount++;
  2362. }
  2363. return compiledPattern;
  2364. };
  2365. /**
  2366. * Public API for matching a URL pathname to a path pattern.
  2367. */
  2368. var matchPath = function matchPath(pathname) {
  2369. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2370. var parent = arguments[2];
  2371. if (typeof options === "string") options = { path: options };
  2372. var _options = options,
  2373. path = _options.path,
  2374. _options$exact = _options.exact,
  2375. exact = _options$exact === undefined ? false : _options$exact,
  2376. _options$strict = _options.strict,
  2377. strict = _options$strict === undefined ? false : _options$strict,
  2378. _options$sensitive = _options.sensitive,
  2379. sensitive = _options$sensitive === undefined ? false : _options$sensitive;
  2380. if (path == null) return parent;
  2381. var _compilePath = compilePath(path, { end: exact, strict: strict, sensitive: sensitive }),
  2382. re = _compilePath.re,
  2383. keys = _compilePath.keys;
  2384. var match = re.exec(pathname);
  2385. if (!match) return null;
  2386. var url = match[0],
  2387. values = match.slice(1);
  2388. var isExact = pathname === url;
  2389. if (exact && !isExact) return null;
  2390. return {
  2391. path: path, // the path pattern used to match
  2392. url: path === "/" && url === "" ? "/" : url, // the matched portion of the URL
  2393. isExact: isExact, // whether or not we matched exactly
  2394. params: keys.reduce(function (memo, key, index) {
  2395. memo[key.name] = values[index];
  2396. return memo;
  2397. }, {})
  2398. };
  2399. };
  2400. var _extends$6 = Object.assign || function (target) {
  2401. for (var i = 1; i < arguments.length; i++) {
  2402. var source = arguments[i];for (var key in source) {
  2403. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2404. target[key] = source[key];
  2405. }
  2406. }
  2407. }return target;
  2408. };
  2409. function _classCallCheck$2(instance, Constructor) {
  2410. if (!(instance instanceof Constructor)) {
  2411. throw new TypeError("Cannot call a class as a function");
  2412. }
  2413. }
  2414. function _possibleConstructorReturn$2(self, call) {
  2415. if (!self) {
  2416. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  2417. }return call && (typeof call === "object" || typeof call === "function") ? call : self;
  2418. }
  2419. function _inherits$2(subClass, superClass) {
  2420. if (typeof superClass !== "function" && superClass !== null) {
  2421. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  2422. }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  2423. }
  2424. var isEmptyChildren = function isEmptyChildren(children) {
  2425. return React.Children.count(children) === 0;
  2426. };
  2427. /**
  2428. * The public API for matching a single path and rendering.
  2429. */
  2430. var Route = function (_React$Component) {
  2431. _inherits$2(Route, _React$Component);
  2432. function Route() {
  2433. var _temp, _this, _ret;
  2434. _classCallCheck$2(this, Route);
  2435. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  2436. args[_key] = arguments[_key];
  2437. }
  2438. return _ret = (_temp = (_this = _possibleConstructorReturn$2(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  2439. match: _this.computeMatch(_this.props, _this.context.router)
  2440. }, _temp), _possibleConstructorReturn$2(_this, _ret);
  2441. }
  2442. Route.prototype.getChildContext = function getChildContext() {
  2443. return {
  2444. router: _extends$6({}, this.context.router, {
  2445. route: {
  2446. location: this.props.location || this.context.router.route.location,
  2447. match: this.state.match
  2448. }
  2449. })
  2450. };
  2451. };
  2452. Route.prototype.computeMatch = function computeMatch(_ref, router) {
  2453. var computedMatch = _ref.computedMatch,
  2454. location = _ref.location,
  2455. path = _ref.path,
  2456. strict = _ref.strict,
  2457. exact = _ref.exact,
  2458. sensitive = _ref.sensitive;
  2459. if (computedMatch) return computedMatch; // <Switch> already computed the match for us
  2460. invariant_1$1(router, "You should not use <Route> or withRouter() outside a <Router>");
  2461. var route = router.route;
  2462. var pathname = (location || route.location).pathname;
  2463. return matchPath(pathname, { path: path, strict: strict, exact: exact, sensitive: sensitive }, route.match);
  2464. };
  2465. Route.prototype.componentWillMount = function componentWillMount() {
  2466. warning_1(!(this.props.component && this.props.render), "You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored");
  2467. warning_1(!(this.props.component && this.props.children && !isEmptyChildren(this.props.children)), "You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored");
  2468. warning_1(!(this.props.render && this.props.children && !isEmptyChildren(this.props.children)), "You should not use <Route render> and <Route children> in the same route; <Route children> will be ignored");
  2469. };
  2470. Route.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) {
  2471. warning_1(!(nextProps.location && !this.props.location), '<Route> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.');
  2472. warning_1(!(!nextProps.location && this.props.location), '<Route> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.');
  2473. this.setState({
  2474. match: this.computeMatch(nextProps, nextContext.router)
  2475. });
  2476. };
  2477. Route.prototype.render = function render() {
  2478. var match = this.state.match;
  2479. var _props = this.props,
  2480. children = _props.children,
  2481. component = _props.component,
  2482. render = _props.render;
  2483. var _context$router = this.context.router,
  2484. history = _context$router.history,
  2485. route = _context$router.route,
  2486. staticContext = _context$router.staticContext;
  2487. var location = this.props.location || route.location;
  2488. var props = { match: match, location: location, history: history, staticContext: staticContext };
  2489. if (component) return match ? React.createElement(component, props) : null;
  2490. if (render) return match ? render(props) : null;
  2491. if (typeof children === "function") return children(props);
  2492. if (children && !isEmptyChildren(children)) return React.Children.only(children);
  2493. return null;
  2494. };
  2495. return Route;
  2496. }(React.Component);
  2497. Route.propTypes = {
  2498. computedMatch: propTypes.object, // private, from <Switch>
  2499. path: propTypes.string,
  2500. exact: propTypes.bool,
  2501. strict: propTypes.bool,
  2502. sensitive: propTypes.bool,
  2503. component: propTypes.func,
  2504. render: propTypes.func,
  2505. children: propTypes.oneOfType([propTypes.func, propTypes.node]),
  2506. location: propTypes.object
  2507. };
  2508. Route.contextTypes = {
  2509. router: propTypes.shape({
  2510. history: propTypes.object.isRequired,
  2511. route: propTypes.object.isRequired,
  2512. staticContext: propTypes.object
  2513. })
  2514. };
  2515. Route.childContextTypes = {
  2516. router: propTypes.object.isRequired
  2517. };
  2518. // Written in this round about way for babel-transform-imports
  2519. /**
  2520. * A <Link> wrapper that knows if it's "active" or not.
  2521. */
  2522. var NavLink = function NavLink(_ref) {
  2523. var to = _ref.to,
  2524. exact = _ref.exact,
  2525. strict = _ref.strict,
  2526. location = _ref.location,
  2527. activeClassName = _ref.activeClassName,
  2528. className = _ref.className,
  2529. activeStyle = _ref.activeStyle,
  2530. style = _ref.style,
  2531. getIsActive = _ref.isActive,
  2532. ariaCurrent = _ref["aria-current"],
  2533. rest = objectWithoutProperties(_ref, ["to", "exact", "strict", "location", "activeClassName", "className", "activeStyle", "style", "isActive", "aria-current"]);
  2534. var path = (typeof to === "undefined" ? "undefined" : _typeof$3(to)) === "object" ? to.pathname : to;
  2535. // Regex taken from: https://github.com/pillarjs/path-to-regexp/blob/master/index.js#L202
  2536. var escapedPath = path && path.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
  2537. return React.createElement(Route, {
  2538. path: escapedPath,
  2539. exact: exact,
  2540. strict: strict,
  2541. location: location,
  2542. children: function children(_ref2) {
  2543. var location = _ref2.location,
  2544. match = _ref2.match;
  2545. var isActive = !!(getIsActive ? getIsActive(match, location) : match);
  2546. return React.createElement(Link, _extends$5({
  2547. to: to,
  2548. className: isActive ? [className, activeClassName].filter(function (i) {
  2549. return i;
  2550. }).join(" ") : className,
  2551. style: isActive ? _extends$5({}, style, activeStyle) : style,
  2552. "aria-current": isActive && ariaCurrent || null
  2553. }, rest));
  2554. }
  2555. });
  2556. };
  2557. NavLink.propTypes = {
  2558. to: Link.propTypes.to,
  2559. exact: propTypes.bool,
  2560. strict: propTypes.bool,
  2561. location: propTypes.object,
  2562. activeClassName: propTypes.string,
  2563. className: propTypes.string,
  2564. activeStyle: propTypes.object,
  2565. style: propTypes.object,
  2566. isActive: propTypes.func,
  2567. "aria-current": propTypes.oneOf(["page", "step", "location", "date", "time", "true"])
  2568. };
  2569. NavLink.defaultProps = {
  2570. activeClassName: "active",
  2571. "aria-current": "page"
  2572. };
  2573. function _classCallCheck$3(instance, Constructor) {
  2574. if (!(instance instanceof Constructor)) {
  2575. throw new TypeError("Cannot call a class as a function");
  2576. }
  2577. }
  2578. function _possibleConstructorReturn$3(self, call) {
  2579. if (!self) {
  2580. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  2581. }return call && (typeof call === "object" || typeof call === "function") ? call : self;
  2582. }
  2583. function _inherits$3(subClass, superClass) {
  2584. if (typeof superClass !== "function" && superClass !== null) {
  2585. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  2586. }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  2587. }
  2588. /**
  2589. * The public API for prompting the user before navigating away
  2590. * from a screen with a component.
  2591. */
  2592. var Prompt = function (_React$Component) {
  2593. _inherits$3(Prompt, _React$Component);
  2594. function Prompt() {
  2595. _classCallCheck$3(this, Prompt);
  2596. return _possibleConstructorReturn$3(this, _React$Component.apply(this, arguments));
  2597. }
  2598. Prompt.prototype.enable = function enable(message) {
  2599. if (this.unblock) this.unblock();
  2600. this.unblock = this.context.router.history.block(message);
  2601. };
  2602. Prompt.prototype.disable = function disable() {
  2603. if (this.unblock) {
  2604. this.unblock();
  2605. this.unblock = null;
  2606. }
  2607. };
  2608. Prompt.prototype.componentWillMount = function componentWillMount() {
  2609. invariant_1$1(this.context.router, "You should not use <Prompt> outside a <Router>");
  2610. if (this.props.when) this.enable(this.props.message);
  2611. };
  2612. Prompt.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  2613. if (nextProps.when) {
  2614. if (!this.props.when || this.props.message !== nextProps.message) this.enable(nextProps.message);
  2615. } else {
  2616. this.disable();
  2617. }
  2618. };
  2619. Prompt.prototype.componentWillUnmount = function componentWillUnmount() {
  2620. this.disable();
  2621. };
  2622. Prompt.prototype.render = function render() {
  2623. return null;
  2624. };
  2625. return Prompt;
  2626. }(React.Component);
  2627. Prompt.propTypes = {
  2628. when: propTypes.bool,
  2629. message: propTypes.oneOfType([propTypes.func, propTypes.string]).isRequired
  2630. };
  2631. Prompt.defaultProps = {
  2632. when: true
  2633. };
  2634. Prompt.contextTypes = {
  2635. router: propTypes.shape({
  2636. history: propTypes.shape({
  2637. block: propTypes.func.isRequired
  2638. }).isRequired
  2639. }).isRequired
  2640. };
  2641. // Written in this round about way for babel-transform-imports
  2642. var patternCache$1 = {};
  2643. var cacheLimit$1 = 10000;
  2644. var cacheCount$1 = 0;
  2645. var compileGenerator = function compileGenerator(pattern) {
  2646. var cacheKey = pattern;
  2647. var cache = patternCache$1[cacheKey] || (patternCache$1[cacheKey] = {});
  2648. if (cache[pattern]) return cache[pattern];
  2649. var compiledGenerator = pathToRegexp_1.compile(pattern);
  2650. if (cacheCount$1 < cacheLimit$1) {
  2651. cache[pattern] = compiledGenerator;
  2652. cacheCount$1++;
  2653. }
  2654. return compiledGenerator;
  2655. };
  2656. /**
  2657. * Public API for generating a URL pathname from a pattern and parameters.
  2658. */
  2659. var generatePath = function generatePath() {
  2660. var pattern = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "/";
  2661. var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  2662. if (pattern === "/") {
  2663. return pattern;
  2664. }
  2665. var generator = compileGenerator(pattern);
  2666. return generator(params, { pretty: true });
  2667. };
  2668. var _extends$7 = Object.assign || function (target) {
  2669. for (var i = 1; i < arguments.length; i++) {
  2670. var source = arguments[i];for (var key in source) {
  2671. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2672. target[key] = source[key];
  2673. }
  2674. }
  2675. }return target;
  2676. };
  2677. function _classCallCheck$4(instance, Constructor) {
  2678. if (!(instance instanceof Constructor)) {
  2679. throw new TypeError("Cannot call a class as a function");
  2680. }
  2681. }
  2682. function _possibleConstructorReturn$4(self, call) {
  2683. if (!self) {
  2684. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  2685. }return call && (typeof call === "object" || typeof call === "function") ? call : self;
  2686. }
  2687. function _inherits$4(subClass, superClass) {
  2688. if (typeof superClass !== "function" && superClass !== null) {
  2689. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  2690. }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  2691. }
  2692. /**
  2693. * The public API for updating the location programmatically
  2694. * with a component.
  2695. */
  2696. var Redirect = function (_React$Component) {
  2697. _inherits$4(Redirect, _React$Component);
  2698. function Redirect() {
  2699. _classCallCheck$4(this, Redirect);
  2700. return _possibleConstructorReturn$4(this, _React$Component.apply(this, arguments));
  2701. }
  2702. Redirect.prototype.isStatic = function isStatic() {
  2703. return this.context.router && this.context.router.staticContext;
  2704. };
  2705. Redirect.prototype.componentWillMount = function componentWillMount() {
  2706. invariant_1$1(this.context.router, "You should not use <Redirect> outside a <Router>");
  2707. if (this.isStatic()) this.perform();
  2708. };
  2709. Redirect.prototype.componentDidMount = function componentDidMount() {
  2710. if (!this.isStatic()) this.perform();
  2711. };
  2712. Redirect.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
  2713. var prevTo = createLocation(prevProps.to);
  2714. var nextTo = createLocation(this.props.to);
  2715. if (locationsAreEqual(prevTo, nextTo)) {
  2716. warning_1(false, "You tried to redirect to the same route you're currently on: " + ("\"" + nextTo.pathname + nextTo.search + "\""));
  2717. return;
  2718. }
  2719. this.perform();
  2720. };
  2721. Redirect.prototype.computeTo = function computeTo(_ref) {
  2722. var computedMatch = _ref.computedMatch,
  2723. to = _ref.to;
  2724. if (computedMatch) {
  2725. if (typeof to === "string") {
  2726. return generatePath(to, computedMatch.params);
  2727. } else {
  2728. return _extends$7({}, to, {
  2729. pathname: generatePath(to.pathname, computedMatch.params)
  2730. });
  2731. }
  2732. }
  2733. return to;
  2734. };
  2735. Redirect.prototype.perform = function perform() {
  2736. var history = this.context.router.history;
  2737. var push = this.props.push;
  2738. var to = this.computeTo(this.props);
  2739. if (push) {
  2740. history.push(to);
  2741. } else {
  2742. history.replace(to);
  2743. }
  2744. };
  2745. Redirect.prototype.render = function render() {
  2746. return null;
  2747. };
  2748. return Redirect;
  2749. }(React.Component);
  2750. Redirect.propTypes = {
  2751. computedMatch: propTypes.object, // private, from <Switch>
  2752. push: propTypes.bool,
  2753. from: propTypes.string,
  2754. to: propTypes.oneOfType([propTypes.string, propTypes.object]).isRequired
  2755. };
  2756. Redirect.defaultProps = {
  2757. push: false
  2758. };
  2759. Redirect.contextTypes = {
  2760. router: propTypes.shape({
  2761. history: propTypes.shape({
  2762. push: propTypes.func.isRequired,
  2763. replace: propTypes.func.isRequired
  2764. }).isRequired,
  2765. staticContext: propTypes.object
  2766. }).isRequired
  2767. };
  2768. // Written in this round about way for babel-transform-imports
  2769. var _extends$8 = Object.assign || function (target) {
  2770. for (var i = 1; i < arguments.length; i++) {
  2771. var source = arguments[i];for (var key in source) {
  2772. if (Object.prototype.hasOwnProperty.call(source, key)) {
  2773. target[key] = source[key];
  2774. }
  2775. }
  2776. }return target;
  2777. };
  2778. function _objectWithoutProperties(obj, keys) {
  2779. var target = {};for (var i in obj) {
  2780. if (keys.indexOf(i) >= 0) continue;if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;target[i] = obj[i];
  2781. }return target;
  2782. }
  2783. function _classCallCheck$5(instance, Constructor) {
  2784. if (!(instance instanceof Constructor)) {
  2785. throw new TypeError("Cannot call a class as a function");
  2786. }
  2787. }
  2788. function _possibleConstructorReturn$5(self, call) {
  2789. if (!self) {
  2790. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  2791. }return call && (typeof call === "object" || typeof call === "function") ? call : self;
  2792. }
  2793. function _inherits$5(subClass, superClass) {
  2794. if (typeof superClass !== "function" && superClass !== null) {
  2795. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  2796. }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  2797. }
  2798. var addLeadingSlash$1 = function addLeadingSlash(path) {
  2799. return path.charAt(0) === "/" ? path : "/" + path;
  2800. };
  2801. var addBasename = function addBasename(basename, location) {
  2802. if (!basename) return location;
  2803. return _extends$8({}, location, {
  2804. pathname: addLeadingSlash$1(basename) + location.pathname
  2805. });
  2806. };
  2807. var stripBasename$1 = function stripBasename(basename, location) {
  2808. if (!basename) return location;
  2809. var base = addLeadingSlash$1(basename);
  2810. if (location.pathname.indexOf(base) !== 0) return location;
  2811. return _extends$8({}, location, {
  2812. pathname: location.pathname.substr(base.length)
  2813. });
  2814. };
  2815. var createURL = function createURL(location) {
  2816. return typeof location === "string" ? location : createPath(location);
  2817. };
  2818. var staticHandler = function staticHandler(methodName) {
  2819. return function () {
  2820. invariant_1$1(false, "You cannot %s with <StaticRouter>", methodName);
  2821. };
  2822. };
  2823. var noop = function noop() {};
  2824. /**
  2825. * The public top-level API for a "static" <Router>, so-called because it
  2826. * can't actually change the current location. Instead, it just records
  2827. * location changes in a context object. Useful mainly in testing and
  2828. * server-rendering scenarios.
  2829. */
  2830. var StaticRouter = function (_React$Component) {
  2831. _inherits$5(StaticRouter, _React$Component);
  2832. function StaticRouter() {
  2833. var _temp, _this, _ret;
  2834. _classCallCheck$5(this, StaticRouter);
  2835. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  2836. args[_key] = arguments[_key];
  2837. }
  2838. return _ret = (_temp = (_this = _possibleConstructorReturn$5(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.createHref = function (path) {
  2839. return addLeadingSlash$1(_this.props.basename + createURL(path));
  2840. }, _this.handlePush = function (location) {
  2841. var _this$props = _this.props,
  2842. basename = _this$props.basename,
  2843. context = _this$props.context;
  2844. context.action = "PUSH";
  2845. context.location = addBasename(basename, createLocation(location));
  2846. context.url = createURL(context.location);
  2847. }, _this.handleReplace = function (location) {
  2848. var _this$props2 = _this.props,
  2849. basename = _this$props2.basename,
  2850. context = _this$props2.context;
  2851. context.action = "REPLACE";
  2852. context.location = addBasename(basename, createLocation(location));
  2853. context.url = createURL(context.location);
  2854. }, _this.handleListen = function () {
  2855. return noop;
  2856. }, _this.handleBlock = function () {
  2857. return noop;
  2858. }, _temp), _possibleConstructorReturn$5(_this, _ret);
  2859. }
  2860. StaticRouter.prototype.getChildContext = function getChildContext() {
  2861. return {
  2862. router: {
  2863. staticContext: this.props.context
  2864. }
  2865. };
  2866. };
  2867. StaticRouter.prototype.componentWillMount = function componentWillMount() {
  2868. warning_1(!this.props.history, "<StaticRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { StaticRouter as Router }`.");
  2869. };
  2870. StaticRouter.prototype.render = function render() {
  2871. var _props = this.props,
  2872. basename = _props.basename,
  2873. context = _props.context,
  2874. location = _props.location,
  2875. props = _objectWithoutProperties(_props, ["basename", "context", "location"]);
  2876. var history = {
  2877. createHref: this.createHref,
  2878. action: "POP",
  2879. location: stripBasename$1(basename, createLocation(location)),
  2880. push: this.handlePush,
  2881. replace: this.handleReplace,
  2882. go: staticHandler("go"),
  2883. goBack: staticHandler("goBack"),
  2884. goForward: staticHandler("goForward"),
  2885. listen: this.handleListen,
  2886. block: this.handleBlock
  2887. };
  2888. return React.createElement(Router, _extends$8({}, props, { history: history }));
  2889. };
  2890. return StaticRouter;
  2891. }(React.Component);
  2892. StaticRouter.propTypes = {
  2893. basename: propTypes.string,
  2894. context: propTypes.object.isRequired,
  2895. location: propTypes.oneOfType([propTypes.string, propTypes.object])
  2896. };
  2897. StaticRouter.defaultProps = {
  2898. basename: "",
  2899. location: "/"
  2900. };
  2901. StaticRouter.childContextTypes = {
  2902. router: propTypes.object.isRequired
  2903. };
  2904. // Written in this round about way for babel-transform-imports
  2905. function _classCallCheck$6(instance, Constructor) {
  2906. if (!(instance instanceof Constructor)) {
  2907. throw new TypeError("Cannot call a class as a function");
  2908. }
  2909. }
  2910. function _possibleConstructorReturn$6(self, call) {
  2911. if (!self) {
  2912. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  2913. }return call && (typeof call === "object" || typeof call === "function") ? call : self;
  2914. }
  2915. function _inherits$6(subClass, superClass) {
  2916. if (typeof superClass !== "function" && superClass !== null) {
  2917. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  2918. }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  2919. }
  2920. /**
  2921. * The public API for rendering the first <Route> that matches.
  2922. */
  2923. var Switch = function (_React$Component) {
  2924. _inherits$6(Switch, _React$Component);
  2925. function Switch() {
  2926. _classCallCheck$6(this, Switch);
  2927. return _possibleConstructorReturn$6(this, _React$Component.apply(this, arguments));
  2928. }
  2929. Switch.prototype.componentWillMount = function componentWillMount() {
  2930. invariant_1$1(this.context.router, "You should not use <Switch> outside a <Router>");
  2931. };
  2932. Switch.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  2933. warning_1(!(nextProps.location && !this.props.location), '<Switch> elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.');
  2934. warning_1(!(!nextProps.location && this.props.location), '<Switch> elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.');
  2935. };
  2936. Switch.prototype.render = function render() {
  2937. var route = this.context.router.route;
  2938. var children = this.props.children;
  2939. var location = this.props.location || route.location;
  2940. var match = void 0,
  2941. child = void 0;
  2942. React.Children.forEach(children, function (element) {
  2943. if (match == null && React.isValidElement(element)) {
  2944. var _element$props = element.props,
  2945. pathProp = _element$props.path,
  2946. exact = _element$props.exact,
  2947. strict = _element$props.strict,
  2948. sensitive = _element$props.sensitive,
  2949. from = _element$props.from;
  2950. var path = pathProp || from;
  2951. child = element;
  2952. match = matchPath(location.pathname, { path: path, exact: exact, strict: strict, sensitive: sensitive }, route.match);
  2953. }
  2954. });
  2955. return match ? React.cloneElement(child, { location: location, computedMatch: match }) : null;
  2956. };
  2957. return Switch;
  2958. }(React.Component);
  2959. Switch.contextTypes = {
  2960. router: propTypes.shape({
  2961. route: propTypes.object.isRequired
  2962. }).isRequired
  2963. };
  2964. Switch.propTypes = {
  2965. children: propTypes.node,
  2966. location: propTypes.object
  2967. };
  2968. // Written in this round about way for babel-transform-imports
  2969. // Written in this round about way for babel-transform-imports
  2970. // Written in this round about way for babel-transform-imports
  2971. var hoistNonReactStatics = createCommonjsModule(function (module, exports) {
  2972. /**
  2973. * Copyright 2015, Yahoo! Inc.
  2974. * Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
  2975. */
  2976. (function (global, factory) {
  2977. module.exports = factory();
  2978. })(commonjsGlobal, function () {
  2979. var REACT_STATICS = {
  2980. childContextTypes: true,
  2981. contextTypes: true,
  2982. defaultProps: true,
  2983. displayName: true,
  2984. getDefaultProps: true,
  2985. getDerivedStateFromProps: true,
  2986. mixins: true,
  2987. propTypes: true,
  2988. type: true
  2989. };
  2990. var KNOWN_STATICS = {
  2991. name: true,
  2992. length: true,
  2993. prototype: true,
  2994. caller: true,
  2995. callee: true,
  2996. arguments: true,
  2997. arity: true
  2998. };
  2999. var defineProperty = Object.defineProperty;
  3000. var getOwnPropertyNames = Object.getOwnPropertyNames;
  3001. var getOwnPropertySymbols = Object.getOwnPropertySymbols;
  3002. var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  3003. var getPrototypeOf = Object.getPrototypeOf;
  3004. var objectPrototype = getPrototypeOf && getPrototypeOf(Object);
  3005. return function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
  3006. if (typeof sourceComponent !== 'string') {
  3007. // don't hoist over string (html) components
  3008. if (objectPrototype) {
  3009. var inheritedComponent = getPrototypeOf(sourceComponent);
  3010. if (inheritedComponent && inheritedComponent !== objectPrototype) {
  3011. hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
  3012. }
  3013. }
  3014. var keys = getOwnPropertyNames(sourceComponent);
  3015. if (getOwnPropertySymbols) {
  3016. keys = keys.concat(getOwnPropertySymbols(sourceComponent));
  3017. }
  3018. for (var i = 0; i < keys.length; ++i) {
  3019. var key = keys[i];
  3020. if (!REACT_STATICS[key] && !KNOWN_STATICS[key] && (!blacklist || !blacklist[key])) {
  3021. var descriptor = getOwnPropertyDescriptor(sourceComponent, key);
  3022. try {
  3023. // Avoid failures from read-only properties
  3024. defineProperty(targetComponent, key, descriptor);
  3025. } catch (e) {}
  3026. }
  3027. }
  3028. return targetComponent;
  3029. }
  3030. return targetComponent;
  3031. };
  3032. });
  3033. });
  3034. var _extends$9 = Object.assign || function (target) {
  3035. for (var i = 1; i < arguments.length; i++) {
  3036. var source = arguments[i];for (var key in source) {
  3037. if (Object.prototype.hasOwnProperty.call(source, key)) {
  3038. target[key] = source[key];
  3039. }
  3040. }
  3041. }return target;
  3042. };
  3043. function _objectWithoutProperties$1(obj, keys) {
  3044. var target = {};for (var i in obj) {
  3045. if (keys.indexOf(i) >= 0) continue;if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;target[i] = obj[i];
  3046. }return target;
  3047. }
  3048. /**
  3049. * A public higher-order component to access the imperative API
  3050. */
  3051. var withRouter = function withRouter(Component) {
  3052. var C = function C(props) {
  3053. var wrappedComponentRef = props.wrappedComponentRef,
  3054. remainingProps = _objectWithoutProperties$1(props, ["wrappedComponentRef"]);
  3055. return React.createElement(Route, {
  3056. children: function children(routeComponentProps) {
  3057. return React.createElement(Component, _extends$9({}, remainingProps, routeComponentProps, {
  3058. ref: wrappedComponentRef
  3059. }));
  3060. }
  3061. });
  3062. };
  3063. C.displayName = "withRouter(" + (Component.displayName || Component.name) + ")";
  3064. C.WrappedComponent = Component;
  3065. C.propTypes = {
  3066. wrappedComponentRef: propTypes.func
  3067. };
  3068. return hoistNonReactStatics(C, Component);
  3069. };
  3070. // Written in this round about way for babel-transform-imports
  3071. exports.BrowserRouter = BrowserRouter;
  3072. exports.HashRouter = HashRouter;
  3073. exports.Link = Link;
  3074. exports.MemoryRouter = MemoryRouter;
  3075. exports.NavLink = NavLink;
  3076. exports.Prompt = Prompt;
  3077. exports.Redirect = Redirect;
  3078. exports.Route = Route;
  3079. exports.Router = Router;
  3080. exports.StaticRouter = StaticRouter;
  3081. exports.Switch = Switch;
  3082. exports.generatePath = generatePath;
  3083. exports.matchPath = matchPath;
  3084. exports.withRouter = withRouter;
  3085. Object.defineProperty(exports, '__esModule', { value: true });
  3086. })));