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