Reputation: 95
After I fill a form in react, and I posted to the working API, I want it to reroute back to /dashboard. I will paste the code that is working
import axios from 'axios';
import { GET_ERRORS } from './types';
const createProject = (project, history) => async dispatch => {
await axios.post('http://localhost:8080/api/project', project)
.catch((error) => {
dispatch({
type: GET_ERRORS,
payload: error.response.data
});
});
};
export default createProject;
Upvotes: 0
Views: 46
Reputation: 7105
use History instead of window.location
// src/actions/userActionCreators.js
// ...
import history from '../history';
import axios from 'axios';
import { GET_ERRORS } from './types';
const createProject = (project, history) => async dispatch => {
await axios.post('http://localhost:8080/api/project', project)
history.push('/');
.catch((error) => {
dispatch({
type: GET_ERRORS,
payload: error.response.data
});
});
};
export default createProject;
Upvotes: 1