简体   繁体   English

React-Router和iframe,浏览器历史记录

[英]React-router and iframe, browser history

I came to the kind of anyoing problem. 我遇到了种种难题。 So, I have a component in react and also using react-router . 所以,我在react有一个组件,也使用react-router Everything works almost great. 一切都很好。 This component has a list of items, when you click on one, it pushes url to the iframe[src={url}] . 该组件具有项目列表,当您单击一个项目时,它将url推送到iframe[src={url}] And here appears the problem, if I will click on several items and then click on the previous page/back button, instead of going to the previous page, it just shows the previous iframe of url that was pushed to iframe. 这就是问题所在,如果我要单击几个项目,然后单击上一页/后退按钮,而不是转到上一页,它只会显示推送到iframe的url的上一个iframe。

What do I do in this situation? 在这种情况下我该怎么办?

@I'm using react-router-dom v4 @我正在使用react-router-dom v4

Don't just change the src. 不要只是更改src。 You've to replace a new iframe everytime the src change. 每次更改src时,您都必须更换一个新的iframe。 By doing that without change things much, just add difference key to your iframe everytime you change src 通过这样做,无需做太多更改,只需在每次更改src时向iframe添加差异密钥

render(){
const iframe = <iframe key={this.thing.id} src={this.thing.src} ></iframe>
return(iframe)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM