需要与重定向帮助在action.js推历史反应路由器V4没有导航
import axios from "axios";
import createHistory from 'history/createBrowserHistory';
import {Notification} from "modules/shared/components";
import * as types from "./actionTypes";
import {API_URL} from "utils/constants";
const history = createHistory();
export function signUp({name, email, password}) {
return (dispatch) => {
dispatch({type: types.AUTH_REQUEST});
axios.post(`${API_URL}/auth/register`, {name, email, password})
.then(response => {
history.push('/');
})
.catch(error => {
const {title, message} = error;
dispatch(Notification('error', title, message));
dispatch({type: types.AUTH_ERROR, payload: error});
})
}
}
在过去,我可以用browserHistory.push('/')
,它将我重定向到/
。使用React Router v4 browserHistory func后,我用createHistory
更改了它。是的它的工作,但它只是改变我的网址,永远不会将我重定向到网址。
任何解决方案?