Reputation: 4050
I want to navigate to a react route after making a post request using the data returned from the post request. What's the correct way to do it using the latest react router?
import {Router} from react-router
.....
.....
fetch(post_request).then(function(response){
return response.json()
}).then(function(response){
this.props.router.push('/new/information/' + response)
})
However this gives me an error saying router is not defined. How can I correctly navigate in react router in this situation? Thanks
Upvotes: 0
Views: 60
Reputation: 281626
You need to call router from context
contextTypes: {
router: React.PropTypes.object.isRequired
}
fetch(post_request).then(function(response){
return response.json()
}).then(function(response){
this.context.router.push('/new/information/' + response)
})
Upvotes: 1