@@ -55,41 +55,49 @@ const Router = React.createClass({
55
55
}
56
56
} ,
57
57
58
- componentWillMount ( ) {
59
- const { transitionManager, router } = this . createRouterObjects ( )
58
+ createRouterObject ( state ) {
59
+ const { matchContext } = this . props
60
+ if ( matchContext ) {
61
+ return matchContext . router
62
+ }
60
63
61
- this . _unlisten = transitionManager . listen ( ( error , state ) => {
62
- if ( error ) {
63
- this . handleError ( error )
64
- } else {
65
- router . location = state . location
66
- router . params = state . params
67
- this . setState ( state , this . props . onUpdate )
68
- }
69
- } )
64
+ const { history } = this . props
65
+ const router = createRouterObject ( history , this . transitionManager )
70
66
71
- this . router = router
67
+ return {
68
+ ...router ,
69
+ location : state . location ,
70
+ params : state . params
71
+ }
72
72
} ,
73
73
74
- createRouterObjects ( ) {
74
+ createTransitionManager ( ) {
75
75
const { matchContext } = this . props
76
76
if ( matchContext ) {
77
- return matchContext
77
+ return matchContext . transitionManager
78
78
}
79
79
80
- let { history } = this . props
80
+ const { history } = this . props
81
81
const { routes, children } = this . props
82
82
83
- const transitionManager = createTransitionManager (
83
+ return createTransitionManager (
84
84
history ,
85
85
createRoutes ( routes || children )
86
86
)
87
+ } ,
87
88
88
- const router = createRouterObject ( history , transitionManager )
89
- router . location = null
90
- router . params = null
89
+ componentWillMount ( ) {
90
+ this . transitionManager = this . createTransitionManager ( )
91
+ this . router = this . createRouterObject ( this . state )
91
92
92
- return { transitionManager, router }
93
+ this . _unlisten = this . transitionManager . listen ( ( error , state ) => {
94
+ if ( error ) {
95
+ this . handleError ( error )
96
+ } else {
97
+ this . router = this . createRouterObject ( state )
98
+ this . setState ( state , this . props . onUpdate )
99
+ }
100
+ } )
93
101
} ,
94
102
95
103
/* istanbul ignore next: sanity check */
0 commit comments