Brand new to react, Attempting to redirect to a \"homepage\" after clicking submit on a \"login\" page. Tried to follow the react router tutorial.
When I click the s
You have to return Redirect in render method (otherwise it will not be rendered and as a result redirection will not happen):
render() {
const redirectToReferrer = this.state.redirectToReferrer;
if (redirectToReferrer) {
return <Redirect to="/home" />
}
// ... rest of render method code
}
I am now able to redirect to the "homepage" by swapping out <Redirect to="/home" /> with this.props.history.push("/home"); using withRouter. Not sure why the first way would not work though.