javascript - 在 React 中触发单击功能时更改 url 位置
问题描述
我是 React 新手,想更改位置或我的 url。我的本地系统上有两个 react 应用程序。一个在端口 3000 上运行,另一个在 3001 上运行。我希望当我单击按钮时,我的 url 从http://localhost:3000
变为http://localhost:3001
当我使用 react-routerhistory.push
时,它不会替换 url,它会附加 url,如:http://localhost:3000/localhost:3001
我也使用window.location = "localhost:3001/"
,但在这种情况下 url 没有改变。
我的代码如下:
<Button type="button" color="primary" onClick={this.handleSubmit}>
handleSubmit = (event) =>{
this.props.history.push('https://localhost:3001');
}
解决方案
你需要使用
window.location.assign("http://localhost:3001");
推荐阅读
- apache-kafka - Kafka 流 KTable 更改日志 TTL
- c# - 在 Bot Framework 中获取用户的注册 Facebook 电子邮件
- ios - 滚动包含 UITextView 的 UICollectionView 时 CPU 使用率 20-25% 是否正常?
- ansible - 如何使用 ansible 从 prometheus.yml 文件中删除特定的行块?
- xsl-fo - 嵌入字体时“读取字体失败”
- asynchronous - 如何等待不返回 Future 的方法?
- mysql - 仅从 mysql 数据库中导出索引
- javascript - Vue.js 方法更改事件不会触发
- css - 块容器如何同时建立块和内联格式化上下文?
- java - spring.profiles.active=native 不适用于 app.yml