I'm using react-router-dom to help handle routing but when I try to switch to the "/" route (my home page) after the user's auth state changes, it does not trigger the redirect. Routes work otherwise throughout the app (via Links). The app is properly reflecting the user state throughout, just not redirecting.
My SignUp component is a class not functional component so I can't use hooks such as useHistory.
Here's my App.tsx:
componentDidMount() {
auth.onAuthStateChanged((user) => {
this.setState({ currentUser: user }, () => {
console.log("this is running")
// up to here is in fact being called when there is a successful sign in
return <Redirect to="/" />;
});
});
}
render() {
return (
<div>
<Header currentUser={this.state.currentUser} />
<Switch>
<Route path="/" exact={true}>
<Home currentUser={this.state.currentUser} key={`home`} />
</Route>
<Route
exact={true}
path="/sign-up"
component={SignUp}
key={`sign-up`}
/>
</Switch>
</div>
);
}
}