Reactjs 无法传递道具值?

Reactjs 无法传递道具值?,reactjs,react-props,prop,Reactjs,React Props,Prop,我是新手,现在将通过props将id从一个页面传递到另一个页面。但我不确定这是不是通过考试的正确方法 考虑以下代码: <div className="submit-button"> <input type="submit" value="Purchase" className="btn btn-primary mt-2 text-capitalize " onClick={this.handleClickPurch

我是新手,现在将通过
props
将id从一个页面传递到另一个页面。但我不确定这是不是通过考试的正确方法

考虑以下代码:

<div  className="submit-button">
    <input type="submit" 
        value="Purchase" 
        className="btn btn-primary mt-2 text-capitalize " 
        onClick={this.handleClickPurchase}
    />
</div>

handleClickPurchase(){
window.location.href='/PurchaseInformation'
返回(
)
}
在我的购买信息页面上

render(props){
    console.log(this.props.value)
    return (
      <div>
        <Header />
        <div>
          <h1> {this.props.value}</h1>
          <h2> Purchase Information Page is under development </h2>
        </div>
      </div>
    );
  }
渲染(道具){
console.log(this.props.value)
返回(
{this.props.value}
购买信息页面正在开发中
);
}

正如@Ido所提到的
返回
没有任何作用

您是否在父组件中呈现
PurchaseInformation
? 如果是这样,只需在渲染函数中使用

我会使用破坏语法,使使用props/object更容易

render(){
   const {value} = this.props;
    console.log(value)
    return (
      <div>
        <Header />
        <div>
          <h1>{value}</h1>
          <h2>Purchase Information Page is under development</h2>
        </div>
      </div>
    );
  }
render(){
const{value}=this.props;
console.log(值)
返回(
{value}
购买信息页面正在开发中
);
}
从handleClickPurchase返回不起任何作用。当您转到新url时,应该使用来呈现新组件。要在页面之间共享信息,您可以使用或使用第三方库,如redux和mobx
render(){
   const {value} = this.props;
    console.log(value)
    return (
      <div>
        <Header />
        <div>
          <h1>{value}</h1>
          <h2>Purchase Information Page is under development</h2>
        </div>
      </div>
    );
  }