1.В компоненте article-List я передаю «историю» дочернему компоненту article-cell:
- В дочернем компоненте (article-cell) я использую 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、