[英]Correctly Navigating to React Route from Javascript
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?
使用最新的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?
在这种情况下,如何正确在React Router中导航? Thanks
谢谢
You need to call router from context
您需要从
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)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.