如何从Angular的ActivatedRoute数据结构中获得运行时路由信息
生活随笔
收集整理的這篇文章主要介紹了
如何从Angular的ActivatedRoute数据结构中获得运行时路由信息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
看個具體的例子:
路由配置信息:
const CUSTOM_ROUTES: Routes = [{ path: "custom/:id", component: RouteDemoComponent } ];RouteDemoComponent的實現:
import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { Observable } from 'rxjs'; import { map } from 'rxjs/operators';@Component({selector: 'app-route-demo',templateUrl: './route-demo.component.html' }) export class RouteDemoComponent implements OnInit {id: Observable<string>;constructor(route: ActivatedRoute) { this.id = 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));}ngOnInit(): void {} }瀏覽器地址欄里輸入:
http://localhost:4200/custom/1
運行時查看ActivatedRoute數據結構的值:
凡是behaviorSubject這種Observable,其_value字段里包含了subscribe被調用后,會emit的實際值:
更多Jerry的原創文章,盡在:“汪子熙”:
總結
以上是生活随笔為你收集整理的如何从Angular的ActivatedRoute数据结构中获得运行时路由信息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦幻西游宠物霜雪龙宝属性怎么样 梦幻西游
- 下一篇: 2022个人所得税申报操作流程,有以下两