连接和withRouter问题 [英] connect and withRouter issue

查看:64
本文介绍了连接和withRouter问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的项目使用Redux和React.我在App.js中有一些路由.我还在项目的react-redux中使用connect函数.为了防止更新阻止问题,我通常以这种方式包装组件

I am using Redux and React for my project. I have some Routes in App.js. I also use the connect function in react-redux in my project. To prevent update blocking issue, I usually wrapped my component in this way

withRouter(connect(mapStateToProps, mapDispatchToProps)(App)),

但是,如果我更改了withRouter的顺序并连接它不起作用:

However, If I changed order of withRouter and connect it doesn't work:

connect(mapStateToProps, mapDispatchToProps)(withRouter(App))

我有console.log App.js中的道具.它已经收到位置和历史道具.我正在弄清楚顺序为什么重要的背后的理论?

I have console.log the props in App.js. It already receives location and history props. I am figuring out the theory behind why the order does matter ?

推荐答案

您可以参考此 https://reacttraining.com/react-router/core/api/withRouter ,它清楚地表明它无法正常工作

Could you refer to this https://reacttraining.com/react-router/core/api/withRouter, it clearly says that it doesn't work the other way around

这篇关于连接和withRouter问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆