I use React router dom in V5.
This is my router:
<Router>
<Switch>
<Route path="/loggedIn">
<LoggedInLandingPage />
</Route>
<Route path="/">
<LandingPage />
</Route>
</Switch>
</Router>
This is my code in my Register Page:
const register = () => {
Axios.post("registration", state)
.then((response) => {
console.log(response);
try
{
setCookie("user", response.data);
history.push("/loggedIn");
}
catch
{
}
})
.catch((error) => {
console.error(error);
})
}
So the URL changed, e.g. from www.domain.com/register to www.domain.com/loggedIn but the website didn't change / refresh. When I now hit F5 everything is fine.
What did I do wrong?
try this
<Router>
<Switch>
<Route exact path="/" component={LandingPage}/>
<Route path="/loggedIn" component={LoggedInLandingPage}>
</Switch>
</Router>