angular - 角度,在重定向中获取标题?
问题描述
我有另一个地址将添加到我在 Angular 9/10 中开发的地址中。它将在标题中传递一些参数,我想在访问我的“/ home”时接收它并从那里采取一些行动。
流程:另一个站点(添加标题)并重定向>我的站点...
ngOnInit() 开始检查是否收到任何标头?
解决方案
Normally ActivatedRoute can be used to get the header data. If you check the documentation of ActivatedRoute, you can use "data" instead of params and get the values.
For an example here based on documentation: https://angular.io/api/router/ActivatedRoute#description
import {Component} from '@angular/core';
/* . . . */
import {ActivatedRoute} from '@angular/router';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators';
/* . . . */
@Component({
/* . . . */
})
export class ActivatedRouteComponent {
constructor(route: ActivatedRoute) {
const id: Observable<string> = route.params.pipe(map(p => p.id));
const url: Observable<string> = route.url.pipe(map(segments => segments.join('')));
// route.data includes both `data` and `resolve`
const user = route.data.pipe(map(d => d.user));
}
}
Here if you see the const user = route.data.pipe(map(d => d.user));, this is what you may need to do.
推荐阅读
- php - 如何使用 spatie/laravel-permission 和 webpatser/laravel-uuid 在 Laravel 中正确实现 UUID?
- google-app-engine - PHP:在谷歌云存储中保存“动态文本或 pdf 内容”?
- python-3.x - 如何在Python循环中提取和分析字典中的数据
- android - Instant App - 安装完整版弹出窗口?
- unix - 存储数学表达式的输出
- google-maps - 出现以下带有 google maps 错误的 JavaScript:NotLoadingAPIFromGoogleMapsError
- react-native - 在 Android/iOS 原生应用中嵌入 React Native 应用
- python-3.x - 为什么我得到一个 KeyError: 'title' with feedparser?
- opengl - 有没有使用 glDrawArrays() 绘制多个不同大小的点的无着色方法?
- php - Illuminate\Routing\Route 类的对象无法转换为字符串