reactjs - 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/register到www.domain.com/loggedIn但网站没有改变/刷新。当我现在按 F5 时,一切都很好。
我做错了什么?
解决方案
尝试
yarn add history@4.7.0
或者
npm install history@4.7.0
推荐阅读
- java - 如何将 Datetime 对象转换为 ZonedDateTime?
- fortran - 在do循环中相互分配相同变量时的段错误
- neural-network - 创建一个简单的神经网络来预测和生成音乐
- css - CSS - :before 选择器不适用于传单地图
- go - 无法从类型 [geo_point] 更改为 xxx
- javascript - 单击时更改 ul 中元素的颜色,但在单击另一个 ul 的元素时保留它
- postgresql - postgres 序列中的 log_cnt 是什么意思?
- c# - 循环在第一次迭代后重置数组的元素?
- pandas - 在seaborn中按升序绘制和重新排列值
- android - 由于依赖问题,Firebase 存储无法正常工作