【发布时间】:2020-06-25 08:27:04
【问题描述】:
我需要使用 react-router 将一个值从一个页面传递到另一个页面。
我试过这样:
<li>
<A
className="btn btn-link btn-sm"
href={{ pathname: Routes.detail_page, search: `?_id=${C.Code}`, state: this.props.current }}>
{ 'Open' }
</A>
</li>
我会将 this.props.current 传递给详细信息页面。
在另一页中,如果我尝试在 componentDidMount() 中打印 this.props.current 它会导致未定义(当然在第一页中这个值是参数化的)。
constructor(props){
super(props);
this.state = {
};
}
componentDidMount(){
let C = this.props.current
console.log("C is: ", C) // this is undefined
this.updateIsDeletableState()
}
我该怎么办?
【问题讨论】:
-
您可以添加您的“其他页面代码”吗?
-
我只尝试在 componentDidMount() 中打印
this.props.currentussign console.log。你需要了解什么? :) -
我想看看你是怎么编码的。
-
我已经编辑了消息
-
确保您的组件中有以下内容,您正在尝试访问道具:```constructor(props){ super(props); this.state = { //状态 }; } ```
标签: javascript reactjs react-router react-router-dom