解决antd布局容器获取不到props的问题

今天在使用Ant Design中提供的布局容器的时候,明明是它一个类组件,但在componentDidMount中输出this.props的时候却得到了一个空对象。

componentDidMount(){
    console.log(this.props)
}    //结果 ==>    {}

这样将无法获取到history等数据,进而难以实现路由跳转等操作。

解决方法:

将结尾暴露的方式进行修改:

原本的:

export default () => <SiderDemo />;

修改后:

export default SiderDemo;

修改后便可获取history,match,location等数据,问题解决。

猜你喜欢

转载自blog.csdn.net/qq_58174484/article/details/124786617
今日推荐