When google index my angular web application. It can't see the pages and in the console I have this error :
SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'https://MYDOMAIN/universe/' cannot be created in a document with origin 'https://webcache.googleusercontent.com' and URL 'https://webcache.googleusercontent.com/search?q=cache:YlVK5uwbqWcJ:https://MYDOMAIN>/universe+&cd=2&hl=fr&ct=clnk&gl=fr'.
But I don't understand the error. Is that mean I have to allow cross origin for webcache.googleusercontent ?
I'm currently using angular universal and nginx as a reverse proxy.
If you want your history to work when accessing your side from google's cache, you need to use relative a URL when you call pushState. AFAIK, there is no cross origin setting that will change this.
The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception
https://developer.mozilla.org/en-US/docs/Web/API/History_API
You could use the hashLocation strategy instead of default path location strategy (https://angular.io/guide/router#appendix-locationstrategy-and-browser-url-styles). This should fix the problem
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot(routes, { useHash: true })
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With