【发布时间】:2018-05-13 21:44:52
【问题描述】:
到处都是,但我对redux-thunk和react-router的想法还不够,但我没有得到这个看似简单的想法:
在操作完成分发到商店后,通过<Route/> 的history.push('/') 以编程方式调用路由更改,这会在按下按钮时发生。
const LoggerRedux = ({stateProp, LogIn}) => {
return(
<div>
<h2>Here is the button. Use this to login</h2>
<Route render={({ history}) => (
<button
type='button'
onClick={
//Something that calls {LogIn}
//and then the history.push('/')
}
>
Log yo Arse Inn
</button>
)}>
</Route>
</div>
)
}
const mapStateToProps = (state) => {
return {
stateProp : state
}
}
const mapDispatchToProps = (dispatch) => {
return {
LogIn : () => dispatch({
type : 'AUTHENTICATE'
}),
LogOut : (bool) => dispatch({
type : 'LOGGED_OUT',
bool
})
}
}
const LoginConn = connect( mapStateToProps, mapDispatchToProps)(LoggerRedux);
我提到/标记的所有事情的通俗解释和示例也很好
【问题讨论】:
标签: reactjs redux react-router react-redux redux-thunk