【问题标题】:ReactJS with react-router Browser History issueReactJS 与 react-router 浏览器历史问题
【发布时间】:2017-03-17 06:00:33
【问题描述】:

我有一个 reactjs 网站,它使用 react-router 和 browserHistory。

今天我发现了一个问题,我不知道如何解决这个问题。 问题是,当我的网站在 iframe 中打开时,例如在谷歌翻译页面中。每次单击链接时,我的网站中的导航不再起作用,它给了我这个错误:

Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'https://www.mywebsite.com/page' cannot be created in a document with origin 'https://translate.googleusercontent.com' and URL 'https://translate.googleusercontent.com/translate_c?depth=2&hl=fr&prev=sear….com&sl=en&u=https://www.mywebsite.com/&usg=ALkJrhiWY47c812s4y3W0cS1VDZX0xRNqA'.

有谁知道我该如何“解决”这个问题?

顺便说一句,我已经使用最新版本的 Chrome 和 Firefox(都在 Windows 上)对此进行了测试

谢谢

【问题讨论】:

  • 在不查看导致错误的代码的情况下帮助您并不容易。

标签: reactjs react-router browser-history


【解决方案1】:

这是一种安全设计。不能跨域推送历史状态。

Mozilla 在这里很好地记录了这个限制: https://developer.mozilla.org/en-US/docs/Web/API/History_API

【讨论】:

    猜你喜欢
    • 2018-01-01
    • 1970-01-01
    • 2017-12-29
    • 2017-08-17
    • 2018-12-26
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    相关资源
    最近更新 更多