BrowserRouter.js 978 B

123456789101112131415161718192021222324252627282930313233343536
  1. import React from "react";
  2. import { Router } from "react-router";
  3. import { createBrowserHistory 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 HTML5 history.
  8. */
  9. class BrowserRouter 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. BrowserRouter.propTypes = {
  17. basename: PropTypes.string,
  18. children: PropTypes.node,
  19. forceRefresh: PropTypes.bool,
  20. getUserConfirmation: PropTypes.func,
  21. keyLength: PropTypes.number
  22. };
  23. BrowserRouter.prototype.componentDidMount = function() {
  24. warning(
  25. !this.props.history,
  26. "<BrowserRouter> ignores the history prop. To use a custom history, " +
  27. "use `import { Router }` instead of `import { BrowserRouter as Router }`."
  28. );
  29. };
  30. }
  31. export default BrowserRouter;