【发布时间】:2019-05-06 08:58:25
【问题描述】:
1.在文章列表组件中,我将“历史”传递给子组件文章单元组件:
- 在子组件(文章单元格)中,我使用history.push,但出现错误。
this.props.history.push(
/detail/${this.props.data._id}, {id: this.props.data_id});
return(
<div>
{
items.map((item,index) => (
<ArticleListCell history={this.props.history} key={index} data={item} tags={tags} />
))
}
</div>
return(
<div className="ac_container" onClick={
() => {
this.props.history.push(`/detail/${this.props.data._id}`, {id: this.props.data_id});
// props.getArticleDetail(props.data_id)
// this.props.his
}
}
>
TypeError: Cannot read property 'push' of undefined
onClick
C:/Users/Lee/Documents/Repos/ReactExpressBlog/src/components/ArticleListCell/ArticleListCell.js:18
15 | return(
16 | <div className="ac_container" onClick={
17 | () => {
> 18 | this.props.history.push(`/detail/${this.props.data._id}`, {id: this.props.data_id});
| ^ 19 | // props.getArticleDetail(props.data_id)
20 | // this.props.his
21 | }
View compiled、
【问题讨论】:
-
article-List 组件中
this.props.history的值是多少?
标签: javascript reactjs react-native react-router