angular - 获取路由上的查询参数,Angular 服务器端渲染
问题描述
是否可以获取查询参数服务器端?我有我的 Angular 应用程序的 Lambda Cloudfront 部署版本。
当平台浏览器发生时,一切正常。
当我尝试获取服务器端的查询参数时,我总是得到空/未定义。
我试过这个:
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 创建的行为中,检查“查询字符串转发和缓存”是否配置为转发特定或所有参数。
推荐阅读
- typescript - type = interface1 或 interface2 ,无法使其工作
- spring-boot - 必须为 oauth2 客户端指定提供程序 ID?
- ios - CVOpenGLESTextureCacheCreateTextureFromImage for kCVPixelFormatType_OneComponent8
- php - 在 PHP 中为数组的每个元素添加键和值
- git - git for-each-ref 字段语法
- html - 如何修复我的 React/ElectronJS 视图的大小?
- outlook-web-addins - AAD for Outlook 加载项中的对话框身份验证
- go - 为什么这个 goroutine 没有运行,即使有一个`time.Sleep`?
- javascript - 有没有办法在 ext js 中重新渲染复选框?
- python - 我可以使用'for'循环,范围函数和一个最初为空的数组来制作一个输出数组,其中包含python中范围内的所有元素吗?