Skip to content

Commit 9d346fc

Browse files
committed
[added] params on RoutingContext child context
1 parent 84ed550 commit 9d346fc

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

modules/RoutingContext.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ class RoutingContext extends Component {
2626

2727
static childContextTypes = {
2828
history: object.isRequired,
29-
location: object.isRequired
29+
location: object.isRequired,
30+
params: object.isRequired
3031
}
3132

3233
getChildContext() {
33-
return {
34-
history: this.props.history,
35-
location: this.props.location
36-
}
34+
const { history, location, params } = this.props
35+
return { history, location, params }
3736
}
3837

3938
createElement(component, props) {

modules/__tests__/RouteComponent-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { render, unmountComponentAtNode } from 'react-dom'
55
import createHistory from 'history/lib/createMemoryHistory'
66
import Router from '../Router'
77

8+
const { object } = React.PropTypes
9+
810
describe('a Route Component', function () {
911

1012
let node
@@ -41,4 +43,28 @@ describe('a Route Component', function () {
4143
), node, done)
4244
})
4345

46+
it('receives the right context', function (done) {
47+
class RouteComponent extends Component {
48+
static contextTypes = {
49+
history: object.isRequired,
50+
location: object.isRequired,
51+
params: object.isRequired
52+
}
53+
componentDidMount() {
54+
expect(this.context.history).toEqual(this.props.history)
55+
expect(this.context.location).toEqual(this.props.location)
56+
expect(this.context.params).toEqual(this.props.params)
57+
}
58+
render() {
59+
return null
60+
}
61+
}
62+
63+
const route = { path: '/', component: RouteComponent }
64+
65+
render((
66+
<Router history={createHistory('/')} routes={route}/>
67+
), node, done)
68+
})
69+
4470
})

0 commit comments

Comments
 (0)