Skip to content

Commit 449fefa

Browse files
committed
Merge pull request #2852 from taion/examples-context-router
Update examples for props.router removal
2 parents 438b6b2 + 53b481b commit 449fefa

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

examples/master-detail/app.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ const Index = React.createClass({
6262
})
6363

6464
const Contact = React.createClass({
65+
contextTypes: {
66+
router: React.PropTypes.object.isRequired
67+
},
6568

6669
getStateFromStore(props) {
6770
const { id } = props ? props.params : this.props.params
@@ -97,7 +100,7 @@ const Contact = React.createClass({
97100
destroy() {
98101
const { id } = this.props.params
99102
ContactStore.removeContact(id)
100-
this.props.router.push('/')
103+
this.context.router.push('/')
101104
},
102105

103106
render() {
@@ -116,6 +119,9 @@ const Contact = React.createClass({
116119
})
117120

118121
const NewContact = React.createClass({
122+
contextTypes: {
123+
router: React.PropTypes.object.isRequired
124+
},
119125

120126
createContact(event) {
121127
event.preventDefault()
@@ -124,7 +130,7 @@ const NewContact = React.createClass({
124130
first: findDOMNode(this.refs.first).value,
125131
last: findDOMNode(this.refs.last).value
126132
}, (contact) => {
127-
this.props.router.push(`/contact/${contact.id}`)
133+
this.context.router.push(`/contact/${contact.id}`)
128134
})
129135
},
130136

examples/passing-props-to-children/app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { browserHistory, Router, Route, Link } from 'react-router'
44
import './app.css'
55

66
const App = React.createClass({
7+
contextTypes: {
8+
router: React.PropTypes.object.isRequired
9+
},
710

811
getInitialState() {
912
return {
@@ -30,7 +33,7 @@ const App = React.createClass({
3033
})
3134
})
3235

33-
this.props.router.push('/')
36+
this.context.router.push('/')
3437
},
3538

3639
render() {

0 commit comments

Comments
 (0)