1
1
import warning from 'warning'
2
2
import invariant from 'invariant'
3
- import Route from './Route'
4
3
import React , { PropTypes } from 'react'
5
4
6
5
/**
@@ -13,12 +12,29 @@ class Router extends React.Component {
13
12
}
14
13
15
14
static childContextTypes = {
16
- history : PropTypes . object . isRequired
15
+ history : PropTypes . object . isRequired ,
16
+ route : PropTypes . object . isRequired
17
17
}
18
18
19
19
getChildContext ( ) {
20
20
return {
21
- history : this . props . history
21
+ history : this . props . history ,
22
+ route : {
23
+ match : this . state . match
24
+ }
25
+ }
26
+ }
27
+
28
+ state = {
29
+ match : this . computeMatch ( this . props . history . location . pathname )
30
+ }
31
+
32
+ computeMatch ( pathname ) {
33
+ return {
34
+ path : '/' ,
35
+ url : '/' ,
36
+ params : { } ,
37
+ isExact : pathname === '/'
22
38
}
23
39
}
24
40
@@ -34,7 +50,9 @@ class Router extends React.Component {
34
50
// location in componentWillMount. This happens e.g. when doing
35
51
// server rendering using a <StaticRouter>.
36
52
this . unlisten = history . listen ( ( ) => {
37
- this . forceUpdate ( )
53
+ this . setState ( {
54
+ match : this . computeMatch ( history . location . pathname )
55
+ } )
38
56
} )
39
57
}
40
58
@@ -51,11 +69,7 @@ class Router extends React.Component {
51
69
52
70
render ( ) {
53
71
const { children } = this . props
54
- return children ? (
55
- < Route path = "/" render = { ( ) => (
56
- React . Children . only ( children )
57
- ) } />
58
- ) : null
72
+ return children ? React . Children . only ( children ) : null
59
73
}
60
74
}
61
75
0 commit comments