【问题标题】:SecurityError: Failed to execute 'replaceState' on 'History':SecurityError:无法在“历史”上执行“replaceState”:
【发布时间】:2018-09-12 07:23:15
【问题描述】:

我在所有浏览器中都面临这个问题。每当我尝试在 Google 缓存中查看我的网站时,就会出现这种情况

main.bundle.js:1 ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'https://mydomainn.com/' cannot be created in a document with origin 'http://webcache.googleusercontent.com'。快递谷歌也存在同样的问题。 http://webcache.googleusercontent.com/search?q=cache%3Ahttps%3A%2F%2Fexpress.google.com%2Fstores&oq=cache%3Ahttps%3A%2F%2Fexpress.google.com%2Fstores&aqs=chrome..69i57j69i58.3999j0j4&sourceid=chrome&ie=UTF-8

我的基本href是/

【问题讨论】:

标签: angular universal server-side-rendering


【解决方案1】:

在你的路线配置中添加

 RouterModule.forRoot(routes, {useHash: true});

在您的 index.html 中执行此操作;

 <!-- <base href="/"> -->
 <script>document.write('<base href="' + document.location + '" />');</script>

然后使用 --base-href ./ 例如构建

ng build --prod --base-href ./

来源https://github.com/angular/angular/issues/13948

【讨论】:

  • 先生,您节省了我的工作日。不能说答案是否解决了这个问题,因为我的问题是不同类型的(服务器上的 index.html 和另一个服务器上的所有应用程序文件)
  • 我自己试图从文件系统加载应用程序并最终得到了这个。很高兴它对你有任何帮助。
  • 我 ajudou muito。谢谢
  • @theeGwandaru,嗨,我在反应服务器端渲染中遇到了同样的问题。能否请您检查stackoverflow.com/questions/63115145/… 如果您能说出可能导致此问题的原因,那就太好了。
猜你喜欢
  • 2018-08-28
  • 1970-01-01
  • 1970-01-01
  • 2020-11-16
  • 2018-05-06
  • 2019-03-29
  • 2018-02-05
  • 2016-02-04
  • 2015-12-05
相关资源
最近更新 更多