@@ -5,7 +5,7 @@ import RoutingContext from './RoutingContext';
5
5
import useRoutes from './useRoutes' ;
6
6
import { routes } from './PropTypes' ;
7
7
8
- var { func } = React . PropTypes ;
8
+ var { func, object } = React . PropTypes ;
9
9
10
10
/**
11
11
* A <Router> is a high-level API for automatically setting up
@@ -15,22 +15,16 @@ var { func } = React.PropTypes;
15
15
var Router = React . createClass ( {
16
16
17
17
propTypes : {
18
+ history : object ,
18
19
children : routes ,
19
20
routes, // alias for children
20
- createHistory : func . isRequired ,
21
21
createElement : func ,
22
22
onError : func ,
23
23
onUpdate : func ,
24
24
parseQueryString : func ,
25
25
stringifyQuery : func
26
26
} ,
27
27
28
- getDefaultProps ( ) {
29
- return {
30
- createHistory : createHashHistory
31
- } ;
32
- } ,
33
-
34
28
getInitialState ( ) {
35
29
return {
36
30
location : null ,
@@ -50,15 +44,16 @@ var Router = React.createClass({
50
44
} ,
51
45
52
46
componentWillMount ( ) {
53
- var { children, routes, parseQueryString, stringifyQuery } = this . props ;
47
+ var { history, children, routes, parseQueryString, stringifyQuery } = this . props ;
48
+ var createHistory = history ? ( ) => history : createHashHistory ;
54
49
55
- this . router = useRoutes ( this . props . createHistory ) ( {
50
+ this . history = useRoutes ( createHistory ) ( {
56
51
routes : createRoutes ( routes || children ) ,
57
52
parseQueryString,
58
53
stringifyQuery
59
54
} ) ;
60
55
61
- this . _unlisten = this . router . listen ( ( error , state ) => {
56
+ this . _unlisten = this . history . listen ( ( error , state ) => {
62
57
if ( error ) {
63
58
this . handleError ( error ) ;
64
59
} else {
@@ -75,7 +70,7 @@ var Router = React.createClass({
75
70
render ( ) {
76
71
return React . createElement ( RoutingContext , {
77
72
...this . state ,
78
- router : this . router ,
73
+ history : this . history ,
79
74
createElement : this . props . createElement
80
75
} ) ;
81
76
}
0 commit comments