无法执行' replaceState'历史记录'

时间:2018-05-12 19:48:49

标签: angular nginx angular-universal

当google索引我的角度Web应用程序时。它无法看到页面,在控制台中我有这个错误:

SecurityError:无法执行' replaceState' on'历史记录':包含网址' https://MYDOMAIN/universe/'的历史状态对象无法在包含来源的文档中创建' https://webcache.googleusercontent.com'和网址' https://webcache.googleusercontent.com/search?q=cache:YlVK5uwbqWcJ:https://MYDOMAIN> / universe +& cd = 2& hl = fr& ct = clnk& gl = fr'。

但我不明白这个错误。这是否意味着我必须允许webcache.googleusercontent的交叉来源?

我目前正在使用angular universal和nginx作为反向代理。

1 个答案:

答案 0 :(得分:1)

如果您希望自己的历史记录在从Google缓存访问您的身边时有效,则在致电pushState时需要使用相对网址。 AFAIK,没有交叉原点设置会改变这一点。

  

新网址必须与当前网址的来源相同;否则,pushState()将抛出异常

https://developer.mozilla.org/en-US/docs/Web/API/History_API

您可以使用hashLocation策略而不是默认路径位置策略(https://angular.io/guide/router#appendix-locationstrategy-and-browser-url-styles)。这个应该解决问题

@NgModule({
  imports: [
  BrowserModule,
  RouterModule.forRoot(routes, { useHash: true }) 
],