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.

HashRouter.js 2.3 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 { createHashHistory as createHistory } from "history";
  8. import Router from "./Router";
  9. /**
  10. * The public API for a <Router> that uses window.location.hash.
  11. */
  12. var HashRouter = function (_React$Component) {
  13. _inherits(HashRouter, _React$Component);
  14. function HashRouter() {
  15. var _temp, _this, _ret;
  16. _classCallCheck(this, HashRouter);
  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. HashRouter.prototype.componentWillMount = function componentWillMount() {
  23. warning(!this.props.history, "<HashRouter> ignores the history prop. To use a custom history, " + "use `import { Router }` instead of `import { HashRouter as Router }`.");
  24. };
  25. HashRouter.prototype.render = function render() {
  26. return React.createElement(Router, { history: this.history, children: this.props.children });
  27. };
  28. return HashRouter;
  29. }(React.Component);
  30. HashRouter.propTypes = {
  31. basename: PropTypes.string,
  32. getUserConfirmation: PropTypes.func,
  33. hashType: PropTypes.oneOf(["hashbang", "noslash", "slash"]),
  34. children: PropTypes.node
  35. };
  36. export default HashRouter;