Angular 获取10中给定url的路由信息

Angular 获取10中给定url的路由信息,angular,angular-router,angular10,Angular,Angular Router,Angular10,在Angular 10中,我的路线中有以下条目: const路由=[ {path:'my/target/:targetId',组件:MyTargetComponent,数据:{dataKey:'dataValue}, ... ] 在我的应用程序中的任何地方,给定任何路径(比如说my/target/55),我需要能够访问我用来定义此类路由的路由对象中包含的所有信息(特别是我需要读取数据字段)。Angular 10中是否有内置函数来执行此操作 更新:我需要访问不一定是当前页面url的url的信息。

在Angular 10中,我的路线中有以下条目:

const路由=[
{path:'my/target/:targetId',组件:MyTargetComponent,数据:{dataKey:'dataValue},
...
]
在我的应用程序中的任何地方,给定任何路径(比如说
my/target/55
),我需要能够访问我用来定义此类路由的路由对象中包含的所有信息(特别是我需要读取
数据
字段)。Angular 10中是否有内置函数来执行此操作

更新:我需要访问不一定是当前页面url的url的信息。

像这样尝试

constructor(private route: Router) {}
ngOnInit() {
    console.log(this.router);
    // on console expand this object and will get all details of routes of complete application in **this.router.config** object.
}

角度路由器将传递动态数据。supose,data:{id:'1',name:“Angular10”}当呈现MyTargetComponent时。数据值将位于ActivatedRoute服务的数据属性中

然后,我们可以通过订阅activatedroute.data属性来读取数据,如下所示:

   ngOnInit() { 
   this.activatedroute.data.subscribe(data => {
       this.product=data;
   }) }
可能是这样的:

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { NavitoComponent } from './navito/navito.component';

export interface Reservas {
  no: number;
  from: Date;
  to: Date;
  name: string;
  price: number;
}

const ko: Reservas[] = [
  { no: 1, from: new Date('07, 15, 2020'), to: new Date('07, 22, 2020'), name: 'Janusz', price: 152.35 },
  { no: 2, from: new Date('07, 17, 2020'), to: new Date('07, 24, 2020'), name: 'Andrzej', price: 152.35 },
  { no: 3, from: new Date('07, 05, 2020'), to: new Date('07, 19, 2020'), name: 'Krzysztof', price: 304.64 },
  { no: 4, from: new Date('07, 15, 2020'), to: new Date('07, 22, 2020'), name: 'Dariusz', price: 152.35 },
  { no: 5, from: new Date('07, 15, 2020'), to: new Date('07, 22, 2020'), name: 'Baltazar', price: 152.35 },
  { no: 6, from: new Date('07, 15, 2020'), to: new Date('07, 22, 2020'), name: 'Mikolaj', price: 152.35 }
];
const routes: Routes = [
  {path: 'myto', component: NavitoComponent, data: {dataKey: ko} }
];
这就是结果


或者尝试了解本地存储和会话存储

这是否回答了您的问题?不幸的是,没有,我已经更新了我的问题。这并不能解决我的问题,我已经更新了我的问题的更多细节。