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