繁体   English   中英

redux不适用于react-router v4

[英]redux doesn't work well with react-router v4

我有一个类似的反应路由器事件

//src/App/components/common/Notifications
onCommentClick = (id) => {
    this.props.history.push(`/dashboard/${id}`)
}

它将更改浏览器网址,我的路由设置正确,我猜

//src/App/containers/dashboard/user/NotificationDetail

但是问题是redux似乎没有重新渲染我的容器组件,我需要刷新以获取正确的内容。

来源https://github.com/thian4/hoc-redux

停留了1天找不到解决方案。

代替这个->

@withRouter
@connect(state => state.global, {
  getNotifications
})

使用mapStateToProps() ->

function mapStateToProps(state) {
     notifications: state.notifications
}

function mapDispatchToProps(dispatch) {
// your actions here
}

export const NotificationsComponent = connect(mapStateToProps)(mapDispatchToProps)(Notifications)

每当您的redux状态更新时,它将重新渲染您的组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM