加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – React Router Redux go操作显示在LogMonitor中,但不

发布时间:2020-12-15 05:06:03 所属栏目:百科 来源:网络整理
导读:我在我的一个视图上使用 react-redux-starter-kit我只是想重定向用户是somethig未设置我的组件相当简单 // MyComponentWithRedirect.jsimport React,{Component,PropTypes} from 'react'import {connect} from 'react-redux'import {go} from 'react-router-
我在我的一个视图上使用 react-redux-starter-kit我只是想重定向用户是somethig未设置我的组件相当简单
// MyComponentWithRedirect.js
import React,{Component,PropTypes} from 'react'
import {connect} from 'react-redux'
import {go} from 'react-router-redux'

class MyComponentWithRedirect extends Component {
  static propTypes = {
    userInfo: PropTypes.object.isRequired,dispatch: PropTypes.func.isRequired
  }

  componentDidMount() {        
    if (this.props.userInfo.firstTime) {
      this.props.dispatch(go('/welcome'))
    }
  }
}

const mapStateToProps = (state) => ({userInfo: state.userInfo})

export default connect(mapStateToProps)(MyComponentWithRedirect)

我可以看到LOCATION_CHANGE操作已触发,但未显示目标视图

我发现我错过了 syncHistoryWithStore的设置,之后它就像使用react-router API的魅力一样
import { browserHistory } from 'react-router'

...
browserHistory.push('/welcome')

我不需要再发送更改位置

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读