我现在遇到的问题是,我不知道如何在发送"FETCH_USER_FULFILLED“(参见https://github.com/DDecoene/React-flux-example/blob/4ab1503dc92d28108f50481a293104ba5d15a29e/app/actions/userActions.js#L17)后更新我的位置。
我正在尝试做的是,对API进行post,当它正常时,切换到索引“页面”
我也尝试过redux-router,但我根本没有让它工作。
发布于 2016-08-17 20:17:34
我建议使用react-router-redux。它附带了push和replace操作,所以你可以在你的操作创建器中dispatch它们。这是一种处理路由更改的更干净的方法,您将在redux dev工具中看到正确的操作。假设您使用redux-thunk中间件:
export const fetchUser = (username, password) => {
return dispatch => {
axios.post(Endpoints.userLogin, {username, password}).then((response) => {
dispatch({type: "FETCH_USER_FULFILLED", payload: response.data});
dispatch(push('/new_location'));
});
};
};发布于 2016-08-17 20:20:02
可能最简单的解决方案是在分派之后使用browserHistory.push():
import { browserHistory } from 'react-router';
...
axios.post(Endpoints.userLogin, {username, password})
.then((response) => {
dispatch({type: "FETCH_USER_FULFILLED", payload: response.data});
browserHistory.push('your/index/route');
})https://stackoverflow.com/questions/38995841
复制相似问题