After I log in react router should redirect me to x route, But not in my case, here is a code of submit.
handleSubmit(e) {
e.preventDefault();
this.setState({
isSubmitting: true,
})
axios.get(`/api/v1/auth/`, {
params: {
email: this.state.email,
password: this.state.password
}
})
.then((response) => {
if (response.data.token) {
localStorage.setItem("Authorization", `Bearer ${response.data.token}`);
console.log('Ok Redirecting');
<Redirect to="/forum" />
}
this.setState({
errorOccurred: true,
isSubmitting: false,
errorMessage: response.data.error
})
}).catch(function (error) {
this.setState({
errorOccurred: true,
isSubmitting: false,
errorMessage: 'Unknow error'
})
});
}
As you can see I expect response.data.token and if everything is ok I would like to redirect the user back to /forum route. I do get console.log'Ok Redirecting' but after that redirection does not take place.
I'm importing only Redirect component from react-router-dom.
This is a bug tracker, not a support system. For usage questions, please use Stack Overflow or Reactiflux. Thanks!