我在V5中使用React router dom。
这是我的路由器:
<Router>
<Switch>
<Route path="/loggedIn">
<LoggedInLandingPage />
</Route>
<Route path="/">
<LandingPage />
</Route>
</Switch>
</Router>
这是我在注册页面中的代码:
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);
})
}
因此 URL 发生了变化,例如从 www.domain.com/register 到 www.domain.com/loggedIn 但网站没有更改/刷新。当我现在按 F5 时,一切都很好。
我做错了什么?
试试这个
<Router>
<Switch>
<Route exact path="/" component={LandingPage}/>
<Route path="/loggedIn" component={LoggedInLandingPage}>
</Switch>
</Router>
当我遇到这个问题时,我发现有两个嵌入式