需要與重定向幫助在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
更改了它。是的它的工作,但它只是改變我的網址,永遠不會將我重定向到網址。
任何解決方案?