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

Ada*_*ung 6 universal server-side-rendering ssr angular

我在所有浏览器中都面临着这个问题.每当我尝试在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是 /

小智 14

在您的路线配置中添加

 RouterModule.forRoot(routes, {useHash: true});
Run Code Online (Sandbox Code Playgroud)

在index.html中执行此操作;

 <!-- <base href="/"> -->
 <script>document.write('<base href="' + document.location + '" />');</script>
Run Code Online (Sandbox Code Playgroud)

然后用--base-href ./构建

ng build --prod --base-href ./
Run Code Online (Sandbox Code Playgroud)

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