UNPKG

2.41 kBJavaScriptView Raw
1function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
3function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
4
5function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } 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; }
6
7import warning from 'warning';
8import React from 'react';
9import PropTypes from 'prop-types';
10import createHistory from 'history/createMemoryHistory';
11import Router from './Router';
12
13/**
14 * The public API for a <Router> that stores location in memory.
15 */
16
17var MemoryRouter = function (_React$Component) {
18 _inherits(MemoryRouter, _React$Component);
19
20 function MemoryRouter() {
21 var _temp, _this, _ret;
22
23 _classCallCheck(this, MemoryRouter);
24
25 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
26 args[_key] = arguments[_key];
27 }
28
29 return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.history = createHistory(_this.props), _temp), _possibleConstructorReturn(_this, _ret);
30 }
31
32 MemoryRouter.prototype.componentWillMount = function componentWillMount() {
33 warning(!this.props.history, '<MemoryRouter> ignores the history prop. To use a custom history, ' + 'use `import { Router }` instead of `import { MemoryRouter as Router }`.');
34 };
35
36 MemoryRouter.prototype.render = function render() {
37 return React.createElement(Router, { history: this.history, children: this.props.children });
38 };
39
40 return MemoryRouter;
41}(React.Component);
42
43MemoryRouter.propTypes = {
44 initialEntries: PropTypes.array,
45 initialIndex: PropTypes.number,
46 getUserConfirmation: PropTypes.func,
47 keyLength: PropTypes.number,
48 children: PropTypes.node
49};
50
51
52export default MemoryRouter;
\No newline at end of file