reactjs - React Router Redux go 操作显示在 LogMonitor 中,但不会更改浏览器上的路径

标签 reactjs redux

我正在使用react-redux-starter-kit根据我的观点之一,我只想重定向用户,但未设置某些内容我的组件相当简单

// 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 操作,但不显示目标 View

enter image description here

最佳答案

我发现我错过了 syncHistoryWithStore 的设置之后,使用react-router API就可以正常工作了

import { browserHistory } from 'react-router'

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

我不再需要调度来更改位置

关于reactjs - React Router Redux go 操作显示在 LogMonitor 中,但不会更改浏览器上的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35755072/

相关文章:

javascript - 无法通过 auth.onAuthStateChanged 中的 currentUser 访问 displayName - Firebase

javascript - React .setState() 中的展开运算符

javascript - 在 redux 应用程序中初始化然后更新 textarea 值。

javascript - 在 redux store 创建后注入(inject)中间件

reactjs - React/Redux 服务器端渲染初始状态

javascript - Redux:Redux 文档示例的 connect 方法中存在奇怪的解构语法?

javascript - 未捕获的不变违规 : Maximum update depth exceeded

javascript - 使用 React Router 隐藏组件

javascript - 使用 React Immutability helpers 或 Immutable js React 合并不可变对象(immutable对象)数组

javascript - 替换深层子对象,同时在 React 中保持状态不可变