reactjs - React:在“react-router-dom”中更改 URL 而不刷新页面:“^4.2.2”
问题描述
我想动态更改我的 url 的 ID,而不需要重新加载页面,但是一旦我更改了 URL,页面就会刷新,并且每次都会调用“componentDidMount()”。
这是我的代码,
`handleSelect(selectedIndex) {
this.props.mediaDetailsProps.history.replace("/post/"+this.props.mediaDetailsProps.match.params.postId+"/media/"+this.props.mediaData[selectedIndex-1].id);
}`
这this.props.mediaData[selectedIndex-1].id
是我的动态内容,它会在每次 handleSelect 函数调用时发生变化。
使用的版本:“react”:“^16.6.3”,“react-router-dom”:“^4.2.2”,
任何帮助表示赞赏。谢谢!
解决方案
推荐阅读
- r - R中数组元素的非连续组合
- html - 使用 Flexbox 不设置任何固定高度的等高图像?
- c - malloc 函数内存分配大小问题
- python - Kaggle 的“SQL 简介”课程中设置了 max_results 值和 to_dataframe 的 list_rows 问题
- javascript - 如何在 React 中设置动态环境配置
- docker - 在 Docker Swarm 中使用模板占位符来绑定卷
- javascript - 无法在 discord.js 上的 channels.get() 内放置变量
- javascript - 如果加载了主页组件,如何直接进入登录页面
- android - android:应用程序被杀死后,后退按钮从工具栏中消失
- apache-flink - Flink 检查点大小正在增长超过 20GB,检查点时间超过 1 分钟