首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在路由上获取查询参数,Angular服务器端渲染

在路由上获取查询参数,Angular服务器端渲染
EN

Stack Overflow用户
提问于 2020-09-24 20:01:04
回答 1查看 245关注 0票数 1

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

当平台浏览器运行时,一切都运行得很好。

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

我已经尝试过了:

代码语言:javascript
复制
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">

并且还尝试了这个:

代码语言:javascript
复制
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的元标签,但我找不到一种方法让它们在服务器端。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-24 20:32:09

似乎是CloudFront配置问题。

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64045999

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档