简体   繁体   English

当我们使用 this.props.history.push("/next Component") 移动到下一个组件时,我们可以传递一个值吗?

[英]can we pass a value when we move to next component using this.props.history.push("/next Component")?

I want to send Task_id to the ShowRecommendation.js component我想将Task_id发送到ShowRecommendation.js组件

  recommend = Task_id => {
        this.props.history.push("/ShowRecommendation");
      };

How it can be done?怎么做?

With react-router you can transfer "state"使用 react-router,您可以传输“状态”

this.props.history.push({
  pathname: '/ShowRecommendation',
  state: { taskid: Task_id }
})

and at the ShowRecommendation.js componenet you can get the value using在 ShowRecommendation.js 组件中,您可以使用以下方法获取值

console.log(this.props.location.state)

Comment if you have more questions如有更多问题请留言

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 this.props.history.push('/') 在 CLASS 组件中不起作用 - this.props.history.push('/') IS NOT WORKING in CLASS Component this.props.history.push() 正在更改 URL 但不执行下一页的操作 - this.props.history.push() is changing the URL but not doing the action to the next page 当我在同一路由中传递回调函数时 this.props.history.push() 不起作用 - this.props.history.push() is not working when i pass the callback function in same route Next JS Layout 组件,将 props 传递给 children - Next JS Layout component, pass props to children 我们可以在 React 中将 props 从 Parent 传递给 Child 组件,并将 props 设置为子组件的 state 吗? - Can we pass props from Parent to Child component in React, and set the props as state of child component? 我们如何使用 React Native 中的 navigationOptions 在功能组件中将状态作为道具传递? - How can we pass state as props in functional component using navigationOptions in React Native? this.props.history.push 在使用 HOC 记录器时不起作用 - this.props.history.push is not working while using HOC for logger 我们可以将 setState 作为 props 从一个组件传递到另一个组件,并在 React 中从子组件更改父状态吗? - Can we pass setState as props from one component to other and change parent state from child component in React? 使用 next/link 将 props 发送到加载的组件 - Send props to a loaded component using next/link ReactJs this.props.history.push()不起作用 - ReactJs this.props.history.push() is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM