微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在路线上获取查询参数,Angular服务器端渲染

是否可以在服务器端获取查询参数? 我有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设置元标记,但我找不到在服务器端将其设置的方法

解决方法

似乎是CloudFront配置问题。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。