首页 > 解决方案 > UseHistory 推送更改 url 但不更改站点

问题描述

我在 V5 中使用反应路由器 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 时,一切都很好。

我做错了什么?

标签: reactjsreact-routerreact-router-dom

解决方案


尝试

yarn add history@4.7.0

或者

npm install history@4.7.0

推荐阅读