UNPKG

978 BJavaScriptView Raw
1import React from "react";
2import PropTypes from "prop-types";
3import { createMemoryHistory as createHistory } from "history";
4import warning from "tiny-warning";
5
6import Router from "./Router";
7
8/**
9 * The public API for a <Router> that stores location in memory.
10 */
11class MemoryRouter extends React.Component {
12 history = createHistory(this.props);
13
14 render() {
15 return <Router history={this.history} children={this.props.children} />;
16 }
17}
18
19if (__DEV__) {
20 MemoryRouter.propTypes = {
21 initialEntries: PropTypes.array,
22 initialIndex: PropTypes.number,
23 getUserConfirmation: PropTypes.func,
24 keyLength: PropTypes.number,
25 children: PropTypes.node
26 };
27
28 MemoryRouter.prototype.componentDidMount = function() {
29 warning(
30 !this.props.history,
31 "<MemoryRouter> ignores the history prop. To use a custom history, " +
32 "use `import { Router }` instead of `import { MemoryRouter as Router }`."
33 );
34 };
35}
36
37export default MemoryRouter;