参考文档: 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
本文详细介绍了如何使用 React Router 实现路由跳转,包括如何在组件中使用 withRouter 高阶组件来访问 history 对象,以及如何通过 push 方法进行路由跳转并传递参数。同时,还介绍了如何在目标组件中接收这些参数。
772

被折叠的 条评论
为什么被折叠?



