我在我的一个视图上使用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)
Run Code Online (Sandbox Code Playgroud)
我可以看到LOCATION_CHANGE操作已触发,但未显示目标视图
我发现我错过了syncHistoryWithStore的设置,之后它就像使用react-router API的魅力一样工作
import { browserHistory } from 'react-router'
...
browserHistory.push('/welcome')
Run Code Online (Sandbox Code Playgroud)
我不再需要派遣来改变地点
| 归档时间: |
|
| 查看次数: |
129 次 |
| 最近记录: |