SecurityError:无法在'History'上执行'replaceState':

问题描述 投票:5回答:1

我在所有浏览器中都面临着这个问题。每当我尝试在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 serverside-rendering ssr
1个回答
14
投票

在您的路线配置中添加

 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

© www.soinside.com 2019 - 2024. All rights reserved.