react-router 4 doesn't update UI when clicking <Link>

随声附和 提交于 2019-12-04 17:28:15

It seems some components, like react-redux containers using connect(), block updates. The problem was solved using withRouter():

const MainContainer = withRouter(connect(
        mapStateToProps,
        mapDispatchToProps
      )(Main));

Documentation: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/docs/api/withRouter.md

I have the same error, but when I use withRouter, nothing changes. In my case, the reason of error is putting the <Link> elements into the <Router> tag.

<Router>
<Link to="something"></Link>
</Router>

Beware of that error, is very hard to diagnose! To fix this, just remove unneccesary <Router> wrapper

Erik Winge almost the right. As I understand component where you enter you need to wrap your Component with withRouter.

So, to fix this you need to add:

...
Main = withRouter(Main);
...
export default Main;
...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!