Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何解决react路由器中的“TypeError:无法读取未定义的属性“push”?_Javascript_Reactjs_React Native_React Router - Fatal编程技术网

Javascript 如何解决react路由器中的“TypeError:无法读取未定义的属性“push”?

Javascript 如何解决react路由器中的“TypeError:无法读取未定义的属性“push”?,javascript,reactjs,react-native,react-router,Javascript,Reactjs,React Native,React Router,1.在项目列表组件中,我将“历史记录”传递给子组件项目单元格组件: 在子componentarticle单元格中,我使用了history.push,但出现了一个错误。 this.props.history.push/detail/${this.props.data.\u id},{id:this.props.data\u id}; 无需将历史作为道具发送给子组件,默认情况下react router dom提供withRouter以获取功能组件中的历史对象。 请参见下面的示例 从“React”导

1.在项目列表组件中,我将“历史记录”传递给子组件项目单元格组件:

在子componentarticle单元格中,我使用了history.push,但出现了一个错误。 this.props.history.push/detail/${this.props.data.\u id},{id:this.props.data\u id};
无需将历史作为道具发送给子组件,默认情况下react router dom提供withRouter以获取功能组件中的历史对象。 请参见下面的示例

从“React”导入React 从“react router dom”导入{withRouter}; 功能测试道具{ const{match,location,history}=props; 常量handleClick==>{ 历史。按“/主页” } 回来 重新使用 } 使用RouterTest导出默认值; 请参见演示代码中的清晰示例

文章列表组件中this.props.history的值是多少?
   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、