Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. "use strict";
  2. exports.__esModule = true;
  3. 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; };
  4. var _warning = require("warning");
  5. var _warning2 = _interopRequireDefault(_warning);
  6. var _invariant = require("invariant");
  7. var _invariant2 = _interopRequireDefault(_invariant);
  8. var _react = require("react");
  9. var _react2 = _interopRequireDefault(_react);
  10. var _propTypes = require("prop-types");
  11. var _propTypes2 = _interopRequireDefault(_propTypes);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14. 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; }
  15. 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; }
  16. /**
  17. * The public API for putting history on context.
  18. */
  19. var Router = function (_React$Component) {
  20. _inherits(Router, _React$Component);
  21. function Router() {
  22. var _temp, _this, _ret;
  23. _classCallCheck(this, Router);
  24. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  25. args[_key] = arguments[_key];
  26. }
  27. return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
  28. match: _this.computeMatch(_this.props.history.location.pathname)
  29. }, _temp), _possibleConstructorReturn(_this, _ret);
  30. }
  31. Router.prototype.getChildContext = function getChildContext() {
  32. return {
  33. router: _extends({}, this.context.router, {
  34. history: this.props.history,
  35. route: {
  36. location: this.props.history.location,
  37. match: this.state.match
  38. }
  39. })
  40. };
  41. };
  42. Router.prototype.computeMatch = function computeMatch(pathname) {
  43. return {
  44. path: "/",
  45. url: "/",
  46. params: {},
  47. isExact: pathname === "/"
  48. };
  49. };
  50. Router.prototype.componentWillMount = function componentWillMount() {
  51. var _this2 = this;
  52. var _props = this.props,
  53. children = _props.children,
  54. history = _props.history;
  55. (0, _invariant2.default)(children == null || _react2.default.Children.count(children) === 1, "A <Router> may have only one child element");
  56. // Do this here so we can setState when a <Redirect> changes the
  57. // location in componentWillMount. This happens e.g. when doing
  58. // server rendering using a <StaticRouter>.
  59. this.unlisten = history.listen(function () {
  60. _this2.setState({
  61. match: _this2.computeMatch(history.location.pathname)
  62. });
  63. });
  64. };
  65. Router.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
  66. (0, _warning2.default)(this.props.history === nextProps.history, "You cannot change <Router history>");
  67. };
  68. Router.prototype.componentWillUnmount = function componentWillUnmount() {
  69. this.unlisten();
  70. };
  71. Router.prototype.render = function render() {
  72. var children = this.props.children;
  73. return children ? _react2.default.Children.only(children) : null;
  74. };
  75. return Router;
  76. }(_react2.default.Component);
  77. Router.propTypes = {
  78. history: _propTypes2.default.object.isRequired,
  79. children: _propTypes2.default.node
  80. };
  81. Router.contextTypes = {
  82. router: _propTypes2.default.object
  83. };
  84. Router.childContextTypes = {
  85. router: _propTypes2.default.object.isRequired
  86. };
  87. exports.default = Router;