【问题标题】:Get Query Params on route, Angular Server Side Rendering获取路由上的查询参数,Angular 服务器端渲染
【发布时间】:2020-09-24 12:01:03
【问题描述】:

是否可以在服务器端获取查询参数? 我有我的 Angular 应用程序的 Lambda Cloudfront 部署版本。

当平台浏览器发生时,一切正常。

当我尝试在服务器端获取查询参数时,我总是得到 null/undefined。

我试过这个:

ngOnInit(): void {
  this.queryId = this.route.snapshot.queryParamMap.get('id');
  this.metaPlatform.addTag({ property: this.queryId, content: this.queryId });
}
//I get this meta tag:
<meta property="null" content="null">

也试过这个:

ngOnInit(): void {
    const snapshot = this.router.routerState.snapshot;
    this.meta.addTag({property: snapshot.url.split('=')[1],content: snapshot.url.split('=')[1]);
}
//I get this meta tag:
<meta property="undefined" content="undefined">

我想根据 queryParams 设置元标记,但我找不到将它们放在服务器端的方法。

【问题讨论】:

    标签: angular server-side-rendering angular-universal query-parameters


    【解决方案1】:

    似乎是 CloudFront 配置问题。

    在 CloudFront 创建的行为中检查“查询字符串转发和缓存”是否配置为转发特定或所有参数。

    【讨论】:

      猜你喜欢
      • 2017-01-22
      • 2016-04-08
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      • 2018-03-13
      • 2015-03-10
      • 2018-03-21
      相关资源
      最近更新 更多