You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MemoryRouter.js 2.4 KiB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2. function _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; }
  3. function _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; }
  4. import warning from "warning";
  5. import React from "react";
  6. import PropTypes from "prop-types";
  7. import { createMemoryHistory as createHistory } from "history";
  8. import Router from "./Router";
  9. /**
  10. * The public API for a <Router> that stores location in memory.
  11. */
  12. var MemoryRouter = function (_React$Component) {
  13. _inherits(MemoryRouter, _React$Component);
  14. function MemoryRouter() {
  15. var _temp, _this, _ret;
  16. _classCallCheck(this, MemoryRouter);
  17. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  18. args[_key] = arguments[_key];
  19. }
  20. 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);
  21. }
  22. MemoryRouter.prototype.componentWillMount = function componentWillMount() {
  23. warning(!this.props.history, "<MemoryRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { MemoryRouter as Router }`.");
  24. };
  25. MemoryRouter.prototype.render = function render() {
  26. return React.createElement(Router, { history: this.history, children: this.props.children });
  27. };
  28. return MemoryRouter;
  29. }(React.Component);
  30. MemoryRouter.propTypes = {
  31. initialEntries: PropTypes.array,
  32. initialIndex: PropTypes.number,
  33. getUserConfirmation: PropTypes.func,
  34. keyLength: PropTypes.number,
  35. children: PropTypes.node
  36. };
  37. export default MemoryRouter;