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

时间:2018-04-03 04:04:03

标签: angular universal serverside-rendering ssr

我在所有浏览器中都遇到了这个问题。每当我尝试在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为/

1 个答案:

答案 0 :(得分: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