react-router4.0如何实现两个子页面之间参数传递

默认展开的是“应用使能平台”页面,radio选择表格中的某一行,id作为参数,需要传递给企业信息的页面。在topic这个组件中,无法通过callback的形式进行参数传递,要如何实现两个子页面之间数据的传递???
clipboard.png

clipboard.png

clipboard.png

阅读 2.4k
2 个回答

笨办法,单击radio时,把id放到state中。然后在topic页面获取这个state就可以了。

router可以这样传呀。

<Link to={`/topic/${selectedId}`}/>
<Router path='/topic/:selectedId' component={/* */} />
//parent
onClick={()=>(this.props.history.push(`/topic`,{selectedId: selectedId}))}
//component
class Index extends Component {
  constructor(props) {
    super(props);
    const { state } = this.props.location;
    let id;
    if (state) {
      if (state.id) {
        id = state.id;
      }
    }
    this.state = {selectedId: id}
    }

不知道这样能不能满足你的需求

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题