我正在使用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
最佳答案
我发现我错过了 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/