首页 > 解决方案 > 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”,

任何帮助表示赞赏。谢谢!

标签: reactjs

解决方案


推荐阅读