File tree Expand file tree Collapse file tree 2 files changed +14
-29
lines changed
packages/react-router/modules Expand file tree Collapse file tree 2 files changed +14
-29
lines changed Original file line number Diff line number Diff line change 1
1
import warning from 'warning'
2
2
import invariant from 'invariant'
3
+ import Route from './Route'
3
4
import React , { PropTypes } from 'react'
4
5
5
6
/**
@@ -18,23 +19,7 @@ class Router extends React.Component {
18
19
19
20
getChildContext ( ) {
20
21
return {
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
+ history : this . props . history
38
23
}
39
24
}
40
25
@@ -50,9 +35,7 @@ class Router extends React.Component {
50
35
// location in componentWillMount. This happens e.g. when doing
51
36
// server rendering using a <StaticRouter>.
52
37
this . unlisten = history . listen ( ( ) => {
53
- this . setState ( {
54
- match : this . computeMatch ( history . location . pathname )
55
- } )
38
+ this . forceUpdate ( )
56
39
} )
57
40
}
58
41
@@ -69,7 +52,11 @@ class Router extends React.Component {
69
52
70
53
render ( ) {
71
54
const { children } = this . props
72
- return children ? React . Children . only ( children ) : null
55
+ return children ? (
56
+ < Route path = "/" render = { ( ) => (
57
+ React . Children . only ( children )
58
+ ) } />
59
+ ) : null
73
60
}
74
61
}
75
62
Original file line number Diff line number Diff line change @@ -89,12 +89,10 @@ describe('A <Router>', () => {
89
89
node
90
90
)
91
91
92
- expect ( rootContext . route ) . toEqual ( {
93
- path : '/' ,
94
- url : '/' ,
95
- params : { } ,
96
- isExact : true
97
- } )
92
+ expect ( rootContext . route . match . path ) . toEqual ( '/' )
93
+ expect ( rootContext . route . match . url ) . toEqual ( '/' )
94
+ expect ( rootContext . route . match . params ) . toEqual ( { } )
95
+ expect ( rootContext . route . match . isExact ) . toEqual ( true )
98
96
} )
99
97
100
98
it ( 'updates context.route upon navigation' , ( ) => {
@@ -109,12 +107,12 @@ describe('A <Router>', () => {
109
107
node
110
108
)
111
109
112
- expect ( rootContext . route . isExact ) . toBe ( true )
110
+ expect ( rootContext . route . match . isExact ) . toBe ( true )
113
111
114
112
const newLocation = { pathname : '/new' }
115
113
history . push ( newLocation )
116
114
117
- expect ( rootContext . route . isExact ) . toBe ( false )
115
+ expect ( rootContext . route . match . isExact ) . toBe ( false )
118
116
} )
119
117
} )
120
118
} )
You can’t perform that action at this time.
0 commit comments