Skip to content

Commit 361e1b5

Browse files
committed
get root context.route tests passing again
we can just use a Route to make a match, no need for special-case code
1 parent c695c48 commit 361e1b5

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

packages/react-router/modules/Router.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import warning from 'warning'
22
import invariant from 'invariant'
3+
import Route from './Route'
34
import React, { PropTypes } from 'react'
45

56
/**
@@ -18,23 +19,7 @@ class Router extends React.Component {
1819

1920
getChildContext() {
2021
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
3823
}
3924
}
4025

@@ -50,9 +35,7 @@ class Router extends React.Component {
5035
// location in componentWillMount. This happens e.g. when doing
5136
// server rendering using a <StaticRouter>.
5237
this.unlisten = history.listen(() => {
53-
this.setState({
54-
match: this.computeMatch(history.location.pathname)
55-
})
38+
this.forceUpdate()
5639
})
5740
}
5841

@@ -69,7 +52,11 @@ class Router extends React.Component {
6952

7053
render() {
7154
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
7360
}
7461
}
7562

packages/react-router/modules/__tests__/Router-test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ describe('A <Router>', () => {
8989
node
9090
)
9191

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)
9896
})
9997

10098
it('updates context.route upon navigation', () => {
@@ -109,12 +107,12 @@ describe('A <Router>', () => {
109107
node
110108
)
111109

112-
expect(rootContext.route.isExact).toBe(true)
110+
expect(rootContext.route.match.isExact).toBe(true)
113111

114112
const newLocation = { pathname: '/new' }
115113
history.push(newLocation)
116114

117-
expect(rootContext.route.isExact).toBe(false)
115+
expect(rootContext.route.match.isExact).toBe(false)
118116
})
119117
})
120118
})

0 commit comments

Comments
 (0)