I have got the url to change to the url I want it to, but the only way I can get it to work is by refreshing the page and then it goes to the url.
An example is lets say I am on localhost:3000/signin and when I sign in I want the user to be redirected to the posts page on localhost:3000/posts. When I click the button I get localhost:3000/posts but the page just stays on the signin page. I have to hit refresh for it to go to that URL.
**********
EDIT: I also noticed that when I hit back or forward in the browser that it isn't rendering till I hit refresh also. So this could be some other issue? I am using react-router-v4.
Here is the code I have so far:
This is the on submit function being called when the button is clicked:
onSubmit({email, password}) {
this.props.signinUser({email, password}, () => {
this.props.history.push('/posts');
});
}
this is the action signinUser:
export function signinUser({email, password}, cb) {
return function(dispatch) {
axios.post(`${ROOT_URL}/signin`, {email, password})
.then((response) => {
dispatch({type: AUTH_USER});
console.log(response);
localStorage.setItem('token', response.data.token);
cb();
})
.catch(() => {
dispatch(authError('bad login info'));
})
}
}