HashRouter.js 962 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React from "react";
  2. import { Router } from "react-router";
  3. import { createHashHistory as createHistory } from "history";
  4. import PropTypes from "prop-types";
  5. import warning from "tiny-warning";
  6. /**
  7. * The public API for a <Router> that uses window.location.hash.
  8. */
  9. class HashRouter extends React.Component {
  10. history = createHistory(this.props);
  11. render() {
  12. return <Router history={this.history} children={this.props.children} />;
  13. }
  14. }
  15. if (__DEV__) {
  16. HashRouter.propTypes = {
  17. basename: PropTypes.string,
  18. children: PropTypes.node,
  19. getUserConfirmation: PropTypes.func,
  20. hashType: PropTypes.oneOf(["hashbang", "noslash", "slash"])
  21. };
  22. HashRouter.prototype.componentDidMount = function() {
  23. warning(
  24. !this.props.history,
  25. "<HashRouter> ignores the history prop. To use a custom history, " +
  26. "use `import { Router }` instead of `import { HashRouter as Router }`."
  27. );
  28. };
  29. }
  30. export default HashRouter;