UseHistory 推送会更改 url,但不会更改网站 [重复]

问题描述 投票:0回答:3

我在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/registerwww.domain.com/loggedIn 但网站没有更改/刷新。当我现在按 F5 时,一切都很好。

我做错了什么?

reactjs react-router react-router-dom
3个回答
1
投票

试试这个

 <Router>
    <Switch>
       <Route exact path="/" component={LandingPage}/>
       <Route path="/loggedIn" component={LoggedInLandingPage}>
    </Switch>
 </Router>

1
投票

尝试

yarn add [email protected]

npm install [email protected]

0
投票

当我遇到这个问题时,我发现有两个嵌入式

© www.soinside.com 2019 - 2024. All rights reserved.