javascript - React-router-dom:History.push 连接路径并且不会重新路由应用程序
问题描述
我有一个包含一堆链接的 popOver:
这是实现它的代码:
<PopoverBody>
<div>
{heart_users_profile_handles.map((heart_user) => (
<div>
<Link
onClick={() => {
this.props.history.push(
`profile/${heart_user.handle}`
);
}}
>
<small>{heart_user.handle}</small>
</Link>
<br />
</div>
))}
</div>
</PopoverBody>
问题在于,当用户单击其中一个链接时,它们并没有被重新路由到它们,而是在浏览器 URL 上连接起来,并且什么也没有发生:
URL原来是这样的:
http://localhost:3000/profile/HamadiAgerbi
单击第一个链接后,会发生这种情况:
http://localhost:3000/profile/profile/AhmedGhrib
在我点击第二个链接后,会发生这种情况:
http://localhost:3000/profile/profile/profile/BarchaHob0
等等等等。
知道是什么原因造成的吗?
解决方案
更改代码。profile/${heart_user.handle}
至/profile/${heart_user.handle}
<PopoverBody>
<div>
{heart_users_profile_handles.map((heart_user) => (
<div>
<Link to={`/profile/${heart_user.handle}`} >
<small>{heart_user.handle}</small>
</Link>
<br />
</div>
))}
</div>
</PopoverBody>
推荐阅读
- javascript - 避免状态更新期间组件内部的刷新功能
- java - 在 ubuntu 错误位置上截取 selenium 中的屏幕截图元素
- angularjs - 我们如何使用 AngularJS v1.3.15 和 bootstrap ui-bootstrap-tpls-0.9.0 实现 typehead 功能
- python - 错误:- 解包的值太多(预期为 2),同时尝试迭代数据框中的两列
- mysql - mysql select和几个条件,但是如果第一个不满足就满足第二个
- javascript - 用paperjs画一个圆圈,里面有一个圆圈空白
- c# - 如何使用自定义渐变画笔绑定颜色
- typescript - 确保对象包含动态键
- java - 如何在android中的活动之间使用EventBus
- python - python“==”如何比较两个标识符