参考文档: react router 文档
import React from "react"
import { withRouter } from "react-router-dom"
class ShowTheLocation extends React.Component {
toOtherRoute = () => {
const urlObj = {
pathname: 'url/url',
state: {
data: 'data'
}
}
this.props.history.push(urlObj)
}
render() {
return (
<div>
<div>hello word</div>
<div onClick={ this.toOtherRoute }>跳转路由</div>
</div>
)
}
}
ShowTheLocation = withRouter(ShowTheLocation)
在跳转过去的组件接收参数:
const { data } = this.props.location.state
总结: 多看官方文档 QAQ