Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SecurityError: Failed to execute 'replaceState' on 'History':

I am facing this issue across all browsers. This comes up whenever I try to view my site in Google cache

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'. The same problem lies with express google. 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.

My base href is /

like image 892
Adam Young Avatar asked Apr 03 '18 04:04

Adam Young


1 Answers

In your routes configuration add

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

In your index.html do this;

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

And then build with --base-href ./ e.g

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

source https://github.com/angular/angular/issues/13948

like image 140
theeGwandaru Avatar answered Sep 18 '22 12:09

theeGwandaru