react-router
Version:
A complete routing library for React
1,631 lines (1,238 loc) • 153 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["ReactRouter"] = factory(require("react"));
else
root["ReactRouter"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.createMemoryHistory = exports.hashHistory = exports.browserHistory = exports.applyRouterMiddleware = exports.formatPattern = exports.useRouterHistory = exports.match = exports.routerShape = exports.locationShape = exports.RouterContext = exports.createRoutes = exports.Route = exports.Redirect = exports.IndexRoute = exports.IndexRedirect = exports.withRouter = exports.IndexLink = exports.Link = exports.Router = undefined;
var _RouteUtils = __webpack_require__(3);
Object.defineProperty(exports, 'createRoutes', {
enumerable: true,
get: function get() {
return _RouteUtils.createRoutes;
}
});
var _PropTypes = __webpack_require__(14);
Object.defineProperty(exports, 'locationShape', {
enumerable: true,
get: function get() {
return _PropTypes.locationShape;
}
});
Object.defineProperty(exports, 'routerShape', {
enumerable: true,
get: function get() {
return _PropTypes.routerShape;
}
});
var _PatternUtils = __webpack_require__(6);
Object.defineProperty(exports, 'formatPattern', {
enumerable: true,
get: function get() {
return _PatternUtils.formatPattern;
}
});
var _Router2 = __webpack_require__(35);
var _Router3 = _interopRequireDefault(_Router2);
var _Link2 = __webpack_require__(20);
var _Link3 = _interopRequireDefault(_Link2);
var _IndexLink2 = __webpack_require__(31);
var _IndexLink3 = _interopRequireDefault(_IndexLink2);
var _withRouter2 = __webpack_require__(46);
var _withRouter3 = _interopRequireDefault(_withRouter2);
var _IndexRedirect2 = __webpack_require__(32);
var _IndexRedirect3 = _interopRequireDefault(_IndexRedirect2);
var _IndexRoute2 = __webpack_require__(33);
var _IndexRoute3 = _interopRequireDefault(_IndexRoute2);
var _Redirect2 = __webpack_require__(22);
var _Redirect3 = _interopRequireDefault(_Redirect2);
var _Route2 = __webpack_require__(34);
var _Route3 = _interopRequireDefault(_Route2);
var _RouterContext2 = __webpack_require__(15);
var _RouterContext3 = _interopRequireDefault(_RouterContext2);
var _match2 = __webpack_require__(44);
var _match3 = _interopRequireDefault(_match2);
var _useRouterHistory2 = __webpack_require__(27);
var _useRouterHistory3 = _interopRequireDefault(_useRouterHistory2);
var _applyRouterMiddleware2 = __webpack_require__(37);
var _applyRouterMiddleware3 = _interopRequireDefault(_applyRouterMiddleware2);
var _browserHistory2 = __webpack_require__(38);
var _browserHistory3 = _interopRequireDefault(_browserHistory2);
var _hashHistory2 = __webpack_require__(42);
var _hashHistory3 = _interopRequireDefault(_hashHistory2);
var _createMemoryHistory2 = __webpack_require__(24);
var _createMemoryHistory3 = _interopRequireDefault(_createMemoryHistory2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.Router = _Router3.default; /* components */
exports.Link = _Link3.default;
exports.IndexLink = _IndexLink3.default;
exports.withRouter = _withRouter3.default;
/* components (configuration) */
exports.IndexRedirect = _IndexRedirect3.default;
exports.IndexRoute = _IndexRoute3.default;
exports.Redirect = _Redirect3.default;
exports.Route = _Route3.default;
/* utils */
exports.RouterContext = _RouterContext3.default;
exports.match = _match3.default;
exports.useRouterHistory = _useRouterHistory3.default;
exports.applyRouterMiddleware = _applyRouterMiddleware3.default;
/* histories */
exports.browserHistory = _browserHistory3.default;
exports.hashHistory = _hashHistory3.default;
exports.createMemoryHistory = _createMemoryHistory3.default;
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var invariant = function(condition, format, a, b, c, d, e, f) {
if (true) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
}
if (!condition) {
var error;
if (format === undefined) {
error = new Error(
'Minified exception occurred; use the non-minified dev environment ' +
'for the full error message and additional helpful warnings.'
);
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
format.replace(/%s/g, function() { return args[argIndex++]; })
);
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
};
module.exports = invariant;
/***/ },
/* 2 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
exports.isReactChildren = isReactChildren;
exports.createRouteFromReactElement = createRouteFromReactElement;
exports.createRoutesFromReactChildren = createRoutesFromReactChildren;
exports.createRoutes = createRoutes;
var _react = __webpack_require__(2);
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isValidChild(object) {
return object == null || _react2.default.isValidElement(object);
}
function isReactChildren(object) {
return isValidChild(object) || Array.isArray(object) && object.every(isValidChild);
}
function createRoute(defaultProps, props) {
return _extends({}, defaultProps, props);
}
function createRouteFromReactElement(element) {
var type = element.type;
var route = createRoute(type.defaultProps, element.props);
if (route.children) {
var childRoutes = createRoutesFromReactChildren(route.children, route);
if (childRoutes.length) route.childRoutes = childRoutes;
delete route.children;
}
return route;
}
/**
* Creates and returns a routes object from the given ReactChildren. JSX
* provides a convenient way to visualize how routes in the hierarchy are
* nested.
*
* import { Route, createRoutesFromReactChildren } from 'react-router'
*
* const routes = createRoutesFromReactChildren(
* <Route component={App}>
* <Route path="home" component={Dashboard}/>
* <Route path="news" component={NewsFeed}/>
* </Route>
* )
*
* Note: This method is automatically used when you provide <Route> children
* to a <Router> component.
*/
function createRoutesFromReactChildren(children, parentRoute) {
var routes = [];
_react2.default.Children.forEach(children, function (element) {
if (_react2.default.isValidElement(element)) {
// Component classes may have a static create* method.
if (element.type.createRouteFromReactElement) {
var route = element.type.createRouteFromReactElement(element, parentRoute);
if (route) routes.push(route);
} else {
routes.push(createRouteFromReactElement(element));
}
}
});
return routes;
}
/**
* Creates and returns an array of routes from the given object which
* may be a JSX route, a plain object route, or an array of either.
*/
function createRoutes(routes) {
if (isReactChildren(routes)) {
routes = createRoutesFromReactChildren(routes);
} else if (routes && !Array.isArray(routes)) {
routes = [routes];
}
return routes;
}
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.createPath = exports.parsePath = exports.getQueryStringValueFromPath = exports.stripQueryStringValueFromPath = exports.addQueryStringValueToPath = undefined;
var _warning = __webpack_require__(5);
var _warning2 = _interopRequireDefault(_warning);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var addQueryStringValueToPath = exports.addQueryStringValueToPath = function addQueryStringValueToPath(path, key, value) {
var _parsePath = parsePath(path);
var pathname = _parsePath.pathname;
var search = _parsePath.search;
var hash = _parsePath.hash;
return createPath({
pathname: pathname,
search: search + (search.indexOf('?') === -1 ? '?' : '&') + key + '=' + value,
hash: hash
});
};
var stripQueryStringValueFromPath = exports.stripQueryStringValueFromPath = function stripQueryStringValueFromPath(path, key) {
var _parsePath2 = parsePath(path);
var pathname = _parsePath2.pathname;
var search = _parsePath2.search;
var hash = _parsePath2.hash;
return createPath({
pathname: pathname,
search: search.replace(new RegExp('([?&])' + key + '=[a-zA-Z0-9]+(&?)'), function (match, prefix, suffix) {
return prefix === '?' ? prefix : suffix;
}),
hash: hash
});
};
var getQueryStringValueFromPath = exports.getQueryStringValueFromPath = function getQueryStringValueFromPath(path, key) {
var _parsePath3 = parsePath(path);
var search = _parsePath3.search;
var match = search.match(new RegExp('[?&]' + key + '=([a-zA-Z0-9]+)'));
return match && match[1];
};
var extractPath = function extractPath(string) {
var match = string.match(/^(https?:)?\/\/[^\/]*/);
return match == null ? string : string.substring(match[0].length);
};
var parsePath = exports.parsePath = function parsePath(path) {
var pathname = extractPath(path);
var search = '';
var hash = '';
true ? (0, _warning2.default)(path === pathname, 'A path must be pathname + search + hash only, not a full URL like "%s"', path) : void 0;
var hashIndex = pathname.indexOf('#');
if (hashIndex !== -1) {
hash = pathname.substring(hashIndex);
pathname = pathname.substring(0, hashIndex);
}
var searchIndex = pathname.indexOf('?');
if (searchIndex !== -1) {
search = pathname.substring(searchIndex);
pathname = pathname.substring(0, searchIndex);
}
if (pathname === '') pathname = '/';
return {
pathname: pathname,
search: search,
hash: hash
};
};
var createPath = exports.createPath = function createPath(location) {
if (location == null || typeof location === 'string') return location;
var basename = location.basename;
var pathname = location.pathname;
var search = location.search;
var hash = location.hash;
var path = (basename || '') + pathname;
if (search && search !== '?') path += search;
if (hash) path += hash;
return path;
};
/***/ },
/* 5 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = function() {};
if (true) {
warning = function(condition, format, args) {
var len = arguments.length;
args = new Array(len > 2 ? len - 2 : 0);
for (var key = 2; key < len; key++) {
args[key - 2] = arguments[key];
}
if (format === undefined) {
throw new Error(
'`warning(condition, format, ...args)` requires a warning ' +
'message argument'
);
}
if (format.length < 10 || (/^[s\W]*$/).test(format)) {
throw new Error(
'The warning format should be able to uniquely identify this ' +
'warning. Please, use a more descriptive format than: ' + format
);
}
if (!condition) {
var argIndex = 0;
var message = 'Warning: ' +
format.replace(/%s/g, function() {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch(x) {}
}
};
}
module.exports = warning;
/***/ },
/* 6 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.compilePattern = compilePattern;
exports.matchPattern = matchPattern;
exports.getParamNames = getParamNames;
exports.getParams = getParams;
exports.formatPattern = formatPattern;
var _invariant = __webpack_require__(1);
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function _compilePattern(pattern) {
var regexpSource = '';
var paramNames = [];
var tokens = [];
var match = void 0,
lastIndex = 0,
matcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|\*\*|\*|\(|\)|\\\(|\\\)/g;
while (match = matcher.exec(pattern)) {
if (match.index !== lastIndex) {
tokens.push(pattern.slice(lastIndex, match.index));
regexpSource += escapeRegExp(pattern.slice(lastIndex, match.index));
}
if (match[1]) {
regexpSource += '([^/]+)';
paramNames.push(match[1]);
} else if (match[0] === '**') {
regexpSource += '(.*)';
paramNames.push('splat');
} else if (match[0] === '*') {
regexpSource += '(.*?)';
paramNames.push('splat');
} else if (match[0] === '(') {
regexpSource += '(?:';
} else if (match[0] === ')') {
regexpSource += ')?';
} else if (match[0] === '\\(') {
regexpSource += '\\(';
} else if (match[0] === '\\)') {
regexpSource += '\\)';
}
tokens.push(match[0]);
lastIndex = matcher.lastIndex;
}
if (lastIndex !== pattern.length) {
tokens.push(pattern.slice(lastIndex, pattern.length));
regexpSource += escapeRegExp(pattern.slice(lastIndex, pattern.length));
}
return {
pattern: pattern,
regexpSource: regexpSource,
paramNames: paramNames,
tokens: tokens
};
}
var CompiledPatternsCache = Object.create(null);
function compilePattern(pattern) {
if (!CompiledPatternsCache[pattern]) CompiledPatternsCache[pattern] = _compilePattern(pattern);
return CompiledPatternsCache[pattern];
}
/**
* Attempts to match a pattern on the given pathname. Patterns may use
* the following special characters:
*
* - :paramName Matches a URL segment up to the next /, ?, or #. The
* captured string is considered a "param"
* - () Wraps a segment of the URL that is optional
* - * Consumes (non-greedy) all characters up to the next
* character in the pattern, or to the end of the URL if
* there is none
* - ** Consumes (greedy) all characters up to the next character
* in the pattern, or to the end of the URL if there is none
*
* The function calls callback(error, matched) when finished.
* The return value is an object with the following properties:
*
* - remainingPathname
* - paramNames
* - paramValues
*/
function matchPattern(pattern, pathname) {
// Ensure pattern starts with leading slash for consistency with pathname.
if (pattern.charAt(0) !== '/') {
pattern = '/' + pattern;
}
var _compilePattern2 = compilePattern(pattern),
regexpSource = _compilePattern2.regexpSource,
paramNames = _compilePattern2.paramNames,
tokens = _compilePattern2.tokens;
if (pattern.charAt(pattern.length - 1) !== '/') {
regexpSource += '/?'; // Allow optional path separator at end.
}
// Special-case patterns like '*' for catch-all routes.
if (tokens[tokens.length - 1] === '*') {
regexpSource += '$';
}
var match = pathname.match(new RegExp('^' + regexpSource, 'i'));
if (match == null) {
return null;
}
var matchedPath = match[0];
var remainingPathname = pathname.substr(matchedPath.length);
if (remainingPathname) {
// Require that the match ends at a path separator, if we didn't match
// the full path, so any remaining pathname is a new path segment.
if (matchedPath.charAt(matchedPath.length - 1) !== '/') {
return null;
}
// If there is a remaining pathname, treat the path separator as part of
// the remaining pathname for properly continuing the match.
remainingPathname = '/' + remainingPathname;
}
return {
remainingPathname: remainingPathname,
paramNames: paramNames,
paramValues: match.slice(1).map(function (v) {
return v && decodeURIComponent(v);
})
};
}
function getParamNames(pattern) {
return compilePattern(pattern).paramNames;
}
function getParams(pattern, pathname) {
var match = matchPattern(pattern, pathname);
if (!match) {
return null;
}
var paramNames = match.paramNames,
paramValues = match.paramValues;
var params = {};
paramNames.forEach(function (paramName, index) {
params[paramName] = paramValues[index];
});
return params;
}
/**
* Returns a version of the given pattern with params interpolated. Throws
* if there is a dynamic segment of the pattern for which there is no param.
*/
function formatPattern(pattern, params) {
params = params || {};
var _compilePattern3 = compilePattern(pattern),
tokens = _compilePattern3.tokens;
var parenCount = 0,
pathname = '',
splatIndex = 0,
parenHistory = [];
var token = void 0,
paramName = void 0,
paramValue = void 0;
for (var i = 0, len = tokens.length; i < len; ++i) {
token = tokens[i];
if (token === '*' || token === '**') {
paramValue = Array.isArray(params.splat) ? params.splat[splatIndex++] : params.splat;
!(paramValue != null || parenCount > 0) ? true ? (0, _invariant2.default)(false, 'Missing splat #%s for path "%s"', splatIndex, pattern) : (0, _invariant2.default)(false) : void 0;
if (paramValue != null) pathname += encodeURI(paramValue);
} else if (token === '(') {
parenHistory[parenCount] = '';
parenCount += 1;
} else if (token === ')') {
var parenText = parenHistory.pop();
parenCount -= 1;
if (parenCount) parenHistory[parenCount - 1] += parenText;else pathname += parenText;
} else if (token === '\\(') {
pathname += '(';
} else if (token === '\\)') {
pathname += ')';
} else if (token.charAt(0) === ':') {
paramName = token.substring(1);
paramValue = params[paramName];
!(paramValue != null || parenCount > 0) ? true ? (0, _invariant2.default)(false, 'Missing "%s" parameter for path "%s"', paramName, pattern) : (0, _invariant2.default)(false) : void 0;
if (paramValue == null) {
if (parenCount) {
parenHistory[parenCount - 1] = '';
var curTokenIdx = tokens.indexOf(token);
var tokensSubset = tokens.slice(curTokenIdx, tokens.length);
var nextParenIdx = -1;
for (var _i = 0; _i < tokensSubset.length; _i++) {
if (tokensSubset[_i] == ')') {
nextParenIdx = _i;
break;
}
}
!(nextParenIdx > 0) ? true ? (0, _invariant2.default)(false, 'Path "%s" is missing end paren at segment "%s"', pattern, tokensSubset.join('')) : (0, _invariant2.default)(false) : void 0;
// jump to ending paren
i = curTokenIdx + nextParenIdx - 1;
}
} else if (parenCount) parenHistory[parenCount - 1] += encodeURIComponent(paramValue);else pathname += encodeURIComponent(paramValue);
} else {
if (parenCount) parenHistory[parenCount - 1] += token;else pathname += token;
}
}
!(parenCount <= 0) ? true ? (0, _invariant2.default)(false, 'Path "%s" is missing end paren', pattern) : (0, _invariant2.default)(false) : void 0;
return pathname.replace(/\/+/g, '/');
}
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.default = routerWarning;
exports._resetWarned = _resetWarned;
var _warning = __webpack_require__(5);
var _warning2 = _interopRequireDefault(_warning);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var warned = {};
function routerWarning(falseToWarn, message) {
// Only issue deprecation warnings once.
if (message.indexOf('deprecated') !== -1) {
if (warned[message]) {
return;
}
warned[message] = true;
}
message = '[react-router] ' + message;
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
_warning2.default.apply(undefined, [falseToWarn, message].concat(args));
}
function _resetWarned() {
warned = {};
}
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.locationsAreEqual = exports.statesAreEqual = exports.createLocation = exports.createQuery = undefined;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _invariant = __webpack_require__(1);
var _invariant2 = _interopRequireDefault(_invariant);
var _warning = __webpack_require__(5);
var _warning2 = _interopRequireDefault(_warning);
var _PathUtils = __webpack_require__(4);
var _Actions = __webpack_require__(10);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var createQuery = exports.createQuery = function createQuery(props) {
return _extends(Object.create(null), props);
};
var createLocation = exports.createLocation = function createLocation() {
var input = arguments.length <= 0 || arguments[0] === undefined ? '/' : arguments[0];
var action = arguments.length <= 1 || arguments[1] === undefined ? _Actions.POP : arguments[1];
var key = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
var object = typeof input === 'string' ? (0, _PathUtils.parsePath)(input) : input;
true ? (0, _warning2.default)(!object.path, 'Location descriptor objects should have a `pathname`, not a `path`.') : void 0;
var pathname = object.pathname || '/';
var search = object.search || '';
var hash = object.hash || '';
var state = object.state;
return {
pathname: pathname,
search: search,
hash: hash,
state: state,
action: action,
key: key
};
};
var isDate = function isDate(object) {
return Object.prototype.toString.call(object) === '[object Date]';
};
var statesAreEqual = exports.statesAreEqual = function statesAreEqual(a, b) {
if (a === b) return true;
var typeofA = typeof a === 'undefined' ? 'undefined' : _typeof(a);
var typeofB = typeof b === 'undefined' ? 'undefined' : _typeof(b);
if (typeofA !== typeofB) return false;
!(typeofA !== 'function') ? true ? (0, _invariant2.default)(false, 'You must not store functions in location state') : (0, _invariant2.default)(false) : void 0;
// Not the same object, but same type.
if (typeofA === 'object') {
!!(isDate(a) && isDate(b)) ? true ? (0, _invariant2.default)(false, 'You must not store Date objects in location state') : (0, _invariant2.default)(false) : void 0;
if (!Array.isArray(a)) {
var keysofA = Object.keys(a);
var keysofB = Object.keys(b);
return keysofA.length === keysofB.length && keysofA.every(function (key) {
return statesAreEqual(a[key], b[key]);
});
}
return Array.isArray(b) && a.length === b.length && a.every(function (item, index) {
return statesAreEqual(item, b[index]);
});
}
// All other serializable types (string, number, boolean)
// should be strict equal.
return false;
};
var locationsAreEqual = exports.locationsAreEqual = function locationsAreEqual(a, b) {
return a.key === b.key &&
// a.action === b.action && // Different action !== location change.
a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && statesAreEqual(a.state, b.state);
};
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.routes = exports.route = exports.components = exports.component = exports.history = undefined;
exports.falsy = falsy;
var _react = __webpack_require__(2);
var func = _react.PropTypes.func,
object = _react.PropTypes.object,
arrayOf = _react.PropTypes.arrayOf,
oneOfType = _react.PropTypes.oneOfType,
element = _react.PropTypes.element,
shape = _react.PropTypes.shape,
string = _react.PropTypes.string;
function falsy(props, propName, componentName) {
if (props[propName]) return new Error('<' + componentName + '> should not have a "' + propName + '" prop');
}
var history = exports.history = shape({
listen: func.isRequired,
push: func.isRequired,
replace: func.isRequired,
go: func.isRequired,
goBack: func.isRequired,
goForward: func.isRequired
});
var component = exports.component = oneOfType([func, string]);
var components = exports.components = oneOfType([component, object]);
var route = exports.route = oneOfType([object, element]);
var routes = exports.routes = oneOfType([route, arrayOf(route)]);
/***/ },
/* 10 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
/**
* Indicates that navigation was caused by a call to history.push.
*/
var PUSH = exports.PUSH = 'PUSH';
/**
* Indicates that navigation was caused by a call to history.replace.
*/
var REPLACE = exports.REPLACE = 'REPLACE';
/**
* Indicates that navigation was caused by some other action such
* as using a browser's back/forward buttons and/or manually manipulating
* the URL in a browser's location bar. This is the default.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate
* for more information.
*/
var POP = exports.POP = 'POP';
/***/ },
/* 11 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
var addEventListener = exports.addEventListener = function addEventListener(node, event, listener) {
return node.addEventListener ? node.addEventListener(event, listener, false) : node.attachEvent('on' + event, listener);
};
var removeEventListener = exports.removeEventListener = function removeEventListener(node, event, listener) {
return node.removeEventListener ? node.removeEventListener(event, listener, false) : node.detachEvent('on' + event, listener);
};
/**
* Returns true if the HTML5 history API is supported. Taken from Modernizr.
*
* https://github.com/Modernizr/Modernizr/blob/master/LICENSE
* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
* changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586
*/
var supportsHistory = exports.supportsHistory = function supportsHistory() {
var ua = window.navigator.userAgent;
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;
return window.history && 'pushState' in window.history;
};
/**
* Returns false if using go(n) with hash history causes a full page reload.
*/
var supportsGoWithoutReloadUsingHash = exports.supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() {
return window.navigator.userAgent.indexOf('Firefox') === -1;
};
/**
* Returns true if browser fires popstate on hash change.
* IE10 and IE11 do not.
*/
var supportsPopstateOnHashchange = exports.supportsPopstateOnHashchange = function supportsPopstateOnHashchange() {
return window.navigator.userAgent.indexOf('Trident') === -1;
};
/***/ },
/* 12 */
/***/ function(module, exports) {
"use strict";
exports.__esModule = true;
exports.loopAsync = loopAsync;
exports.mapAsync = mapAsync;
function loopAsync(turns, work, callback) {
var currentTurn = 0,
isDone = false;
var sync = false,
hasNext = false,
doneArgs = void 0;
function done() {
isDone = true;
if (sync) {
// Iterate instead of recursing if possible.
doneArgs = [].concat(Array.prototype.slice.call(arguments));
return;
}
callback.apply(this, arguments);
}
function next() {
if (isDone) {
return;
}
hasNext = true;
if (sync) {
// Iterate instead of recursing if possible.
return;
}
sync = true;
while (!isDone && currentTurn < turns && hasNext) {
hasNext = false;
work.call(this, currentTurn++, next, done);
}
sync = false;
if (isDone) {
// This means the loop finished synchronously.
callback.apply(this, doneArgs);
return;
}
if (currentTurn >= turns && hasNext) {
isDone = true;
callback();
}
}
next();
}
function mapAsync(array, work, callback) {
var length = array.length;
var values = [];
if (length === 0) return callback(null, values);
var isDone = false,
doneCount = 0;
function done(index, error, value) {
if (isDone) return;
if (error) {
isDone = true;
callback(error);
} else {
values[index] = value;
isDone = ++doneCount === length;
if (isDone) callback(null, values);
}
}
array.forEach(function (item, index) {
work(item, index, function (error, value) {
done(index, error, value);
});
});
}
/***/ },
/* 13 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.ContextProvider = ContextProvider;
exports.ContextSubscriber = ContextSubscriber;
var _react = __webpack_require__(2);
// Works around issues with context updates failing to propagate.
// Caveat: the context value is expected to never change its identity.
// https://github.com/facebook/react/issues/2517
// https://github.com/reactjs/react-router/issues/470
var contextProviderShape = _react.PropTypes.shape({
subscribe: _react.PropTypes.func.isRequired,
eventIndex: _react.PropTypes.number.isRequired
});
function makeContextName(name) {
return '@@contextSubscriber/' + name;
}
function ContextProvider(name) {
var _childContextTypes, _ref2;
var contextName = makeContextName(name);
var listenersKey = contextName + '/listeners';
var eventIndexKey = contextName + '/eventIndex';
var subscribeKey = contextName + '/subscribe';
return _ref2 = {
childContextTypes: (_childContextTypes = {}, _childContextTypes[contextName] = contextProviderShape.isRequired, _childContextTypes),
getChildContext: function getChildContext() {
var _ref;
return _ref = {}, _ref[contextName] = {
eventIndex: this[eventIndexKey],
subscribe: this[subscribeKey]
}, _ref;
},
componentWillMount: function componentWillMount() {
this[listenersKey] = [];
this[eventIndexKey] = 0;
},
componentWillReceiveProps: function componentWillReceiveProps() {
this[eventIndexKey]++;
},
componentDidUpdate: function componentDidUpdate() {
var _this = this;
this[listenersKey].forEach(function (listener) {
return listener(_this[eventIndexKey]);
});
}
}, _ref2[subscribeKey] = function (listener) {
var _this2 = this;
// No need to immediately call listener here.
this[listenersKey].push(listener);
return function () {
_this2[listenersKey] = _this2[listenersKey].filter(function (item) {
return item !== listener;
});
};
}, _ref2;
}
function ContextSubscriber(name) {
var _contextTypes, _ref4;
var contextName = makeContextName(name);
var lastRenderedEventIndexKey = contextName + '/lastRenderedEventIndex';
var handleContextUpdateKey = contextName + '/handleContextUpdate';
var unsubscribeKey = contextName + '/unsubscribe';
return _ref4 = {
contextTypes: (_contextTypes = {}, _contextTypes[contextName] = contextProviderShape, _contextTypes),
getInitialState: function getInitialState() {
var _ref3;
if (!this.context[contextName]) {
return {};
}
return _ref3 = {}, _ref3[lastRenderedEventIndexKey] = this.context[contextName].eventIndex, _ref3;
},
componentDidMount: function componentDidMount() {
if (!this.context[contextName]) {
return;
}
this[unsubscribeKey] = this.context[contextName].subscribe(this[handleContextUpdateKey]);
},
componentWillReceiveProps: function componentWillReceiveProps() {
var _setState;
if (!this.context[contextName]) {
return;
}
this.setState((_setState = {}, _setState[lastRenderedEventIndexKey] = this.context[contextName].eventIndex, _setState));
},
componentWillUnmount: function componentWillUnmount() {
if (!this[unsubscribeKey]) {
return;
}
this[unsubscribeKey]();
this[unsubscribeKey] = null;
}
}, _ref4[handleContextUpdateKey] = function (eventIndex) {
if (eventIndex !== this.state[lastRenderedEventIndexKey]) {
var _setState2;
this.setState((_setState2 = {}, _setState2[lastRenderedEventIndexKey] = eventIndex, _setState2));
}
}, _ref4;
}
/***/ },
/* 14 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.locationShape = exports.routerShape = undefined;
var _react = __webpack_require__(2);
var func = _react.PropTypes.func,
object = _react.PropTypes.object,
shape = _react.PropTypes.shape,
string = _react.PropTypes.string;
var routerShape = exports.routerShape = shape({
push: func.isRequired,
replace: func.isRequired,
go: func.isRequired,
goBack: func.isRequired,
goForward: func.isRequired,
setRouteLeaveHook: func.isRequired,
isActive: func.isRequired
});
var locationShape = exports.locationShape = shape({
pathname: string.isRequired,
search: string.isRequired,
state: object,
action: string.isRequired,
key: string
});
/***/ },
/* 15 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _invariant = __webpack_require__(1);
var _invariant2 = _interopRequireDefault(_invariant);
var _react = __webpack_require__(2);
var _react2 = _interopRequireDefault(_react);
var _getRouteParams = __webpack_require__(41);
var _getRouteParams2 = _interopRequireDefault(_getRouteParams);
var _ContextUtils = __webpack_require__(13);
var _RouteUtils = __webpack_require__(3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _React$PropTypes = _react2.default.PropTypes,
array = _React$PropTypes.array,
func = _React$PropTypes.func,
object = _React$PropTypes.object;
/**
* A <RouterContext> renders the component tree for a given router state
* and sets the history object and the current location in context.
*/
var RouterContext = _react2.default.createClass({
displayName: 'RouterContext',
mixins: [(0, _ContextUtils.ContextProvider)('router')],
propTypes: {
router: object.isRequired,
location: object.isRequired,
routes: array.isRequired,
params: object.isRequired,
components: array.isRequired,
createElement: func.isRequired
},
getDefaultProps: function getDefaultProps() {
return {
createElement: _react2.default.createElement
};
},
childContextTypes: {
router: object.isRequired
},
getChildContext: function getChildContext() {
return {
router: this.props.router
};
},
createElement: function createElement(component, props) {
return component == null ? null : this.props.createElement(component, props);
},
render: function render() {
var _this = this;
var _props = this.props,
location = _props.location,
routes = _props.routes,
params = _props.params,
components = _props.components,
router = _props.router;
var element = null;
if (components) {
element = components.reduceRight(function (element, components, index) {
if (components == null) return element; // Don't create new children; use the grandchildren.
var route = routes[index];
var routeParams = (0, _getRouteParams2.default)(route, params);
var props = {
location: location,
params: params,
route: route,
router: router,
routeParams: routeParams,
routes: routes
};
if ((0, _RouteUtils.isReactChildren)(element)) {
props.children = element;
} else if (element) {
for (var prop in element) {
if (Object.prototype.hasOwnProperty.call(element, prop)) props[prop] = element[prop];
}
}
if ((typeof components === 'undefined' ? 'undefined' : _typeof(components)) === 'object') {
var elements = {};
for (var key in components) {
if (Object.prototype.hasOwnProperty.call(components, key)) {
// Pass through the key as a prop to createElement to allow
// custom createElement functions to know which named component
// they're rendering, for e.g. matching up to fetched data.
elements[key] = _this.createElement(components[key], _extends({
key: key }, props));
}
}
return elements;
}
return _this.createElement(components, props);
}, element);
}
!(element === null || element === false || _react2.default.isValidElement(element)) ? true ? (0, _invariant2.default)(false, 'The root route must render a single element') : (0, _invariant2.default)(false) : void 0;
return element;
}
});
exports.default = RouterContext;
/***/ },
/* 16 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
exports.go = exports.replaceLocation = exports.pushLocation = exports.startListener = exports.getUserConfirmation = exports.getCurrentLocation = undefined;
var _LocationUtils = __webpack_require__(8);
var _DOMUtils = __webpack_require__(11);
var _DOMStateStorage = __webpack_require__(28);
var _PathUtils = __webpack_require__(4);
var _ExecutionEnvironment = __webpack_require__(17);
var PopStateEvent = 'popstate';
var HashChangeEvent = 'hashchange';
var needsHashchangeListener = _ExecutionEnvironment.canUseDOM && !(0, _DOMUtils.supportsPopstateOnHashchange)();
var _createLocation = function _createLocation(historyState) {
var key = historyState && historyState.key;
return (0, _LocationUtils.createLocation)({
pathname: window.location.pathname,
search: window.location.search,
hash: window.location.hash,
state: key ? (0, _DOMStateStorage.readState)(key) : undefined
}, undefined, key);
};
var getCurrentLocation = exports.getCurrentLocation = function getCurrentLocation() {
var historyState = void 0;
try {
historyState = window.history.state || {};
} catch (error) {
// IE 11 sometimes throws when accessing window.history.state
// See https://github.com/ReactTraining/history/pull/289
historyState = {};
}
return _createLocation(historyState);
};
var getUserConfirmation = exports.getUserConfirmation = function getUserConfirmation(message, callback) {
return callback(window.confirm(message));
}; // eslint-disable-line no-alert
var startListener = exports.startListener = function startListener(listener) {
var handlePopState = function handlePopState(event) {
if (event.state !== undefined) // Ignore extraneous popstate events in WebKit
listener(_createLocation(event.state));
};
(0, _DOMUtils.addEventListener)(window, PopStateEvent, handlePopState);
var handleUnpoppedHashChange = function handleUnpoppedHashChange() {
return listener(getCurrentLocation());
};
if (needsHashchangeListener) {
(0, _DOMUtils.addEventListener)(window, HashChangeEvent, handleUnpoppedHashChange);
}
return function () {
(0, _DOMUtils.removeEventListener)(window, PopStateEvent, handlePopState);
if (needsHashchangeListener) {
(0, _DOMUtils.removeEventListener)(window, HashChangeEvent, handleUnpoppedHashChange);
}
};
};
var updateLocation = function updateLocation(location, updateState) {
var state = location.state;
var key = location.key;
if (state !== undefined) (0, _DOMStateStorage.saveState)(key, state);
updateState({ key: key }, (0, _PathUtils.createPath)(location));
};
var pushLocation = exports.pushLocation = function pushLocation(location) {
return updateLocation(location, function (state, path) {
return window.history.pushState(state, null, path);
});
};
var replaceLocation = exports.replaceLocation = function replaceLocation(location) {
return updateLocation(location, function (state, path) {
return window.history.replaceState(state, null, path);
});
};
var go = exports.go = function go(n) {
if (n) window.history.go(n);
};
/***/ },
/* 17 */
/***/ function(module, exports) {
'use strict';
exports.__esModule = true;
var canUseDOM = exports.canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
/***/ },
/* 18 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _AsyncUtils = __webpack_require__(47);
var _PathUtils = __webpack_require__(4);
var _runTransitionHook = __webpack_require__(19);
var _runTransitionHook2 = _interopRequireDefault(_runTransitionHook);
var _Actions = __webpack_require__(10);
var _LocationUtils = __webpack_require__(8);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var createHistory = function createHistory() {
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var getCurrentLocation = options.getCurrentLocation;
var getUserConfirmation = options.getUserConfirmation;
var pushLocation = options.pushLocation;
var replaceLocation = options.replaceLocation;
var go = options.go;
var keyLength = options.keyLength;
var currentLocation = void 0;
var pendingLocation = void 0;
var beforeListeners = [];
var listeners = [];
var allKeys = [];
var getCurrentIndex = function getCurrentIndex() {
if (pendingLocation && pendingLocation.action === _Actions.POP) return allKeys.indexOf(pendingLocation.key);
if (currentLocation) return allKeys.indexOf(currentLocation.key);
return -1;
};
var updateLocation = function updateLocation(nextLocation) {
var currentIndex = getCurrentIndex();
currentLocation = nextLocation;
if (currentLocation.action === _Actions.PUSH) {
allKeys = [].concat(allKeys.slice(0, currentIndex + 1), [currentLocation.key]);
} else if (currentLocation.action === _Actions.REPLACE) {
allKeys[currentIndex] = currentLocation.key;
}
listeners.forEach(function (listener) {
return listener(currentLocation);
});
};
var listenBefore = function listenBefore(listener) {
beforeListeners.push(listener);
return function () {
return beforeListeners = beforeListeners.filter(function (item) {
return item !== listener;
});
};
};
var listen = function listen(listener) {
listeners.push(listener);
return function () {
return listeners = listeners.filter(function (item) {
return item !== listener;
});
};
};
var confirmTransitionTo = function confirmTransitionTo(location, callback) {
(0, _AsyncUtils.loopAsync)(beforeListeners.length, function (index, next, done) {
(0, _runTransitionHook2.default)(beforeListeners[index], location, function (result) {
return result != null ? done(result) : next();
});
}, function (message) {
if (getUserConfirmation && typeof message === 'string') {
getUserConfirmation(message, function (ok) {
return callback(ok !== false);
});
} else {
callback(message !== false);
}
});
};
var transitionTo = function transitionTo(nextLocation) {
if (currentLocation && (0, _LocationUtils.locationsAreEqual)(currentLocation, nextLocation) || pendingLocation && (0, _LocationUtils.locationsAreEqual)(pendingLocation, nextLocation)) return; // Nothing to do
pendingLocation = nextLocation;
confirmTransitionTo(nextLocation, function (ok) {
if (pendingLocation !== nextLocation) return; // Transition was interrupted during confirmation
pendingLocation = null;
if (ok) {
// Treat PUSH to same path like REPLACE to be consistent with browsers
if (nextLocation.action === _Actions.PUSH) {
var prevPath = (0, _PathUtils.createPath)(currentLocation);
var nextPath = (0, _PathUtils.createPath)(nextLocation);
if (nextPath === prevPath && (0, _LocationUtils.statesAreEqual)(currentLocation.state, nextLocation.state)) nextLocation.action = _Actions.REPLACE;
}
if (nextLocation.action === _Actions.POP) {
updateLocation(nextLocation);