我决定将所有逻辑从React Components转移到Action Creators中。为此,我将经典的Redux动作创建器迁移到异步Redux-Thunk动作创建器。
基本流程非常出色。但我不知道如何从异步Action Creators更新路由器:(
import axios from 'axios';
import * as dialogActions from './DialogActions';
export const login = (creds) => {
return (dispatch) => {
axios.post('/admin/login', creds)
.then((res) => {
localStorage.setItem("token", res.headers['authorization']);
//Next line gives error
this.props.history.push("/admin/home");
dispatch(dialogActions.initErrorAction(false, ''));
})
.catch((err) => {
console.log(err.message)
dispatch(dialogActions.initErrorAction(true, 'Invalid email or password'));
});
}
}
所以问题是:如何从Redux-Thunk Action Creators更新路由器?