Angular 使用延迟加载以角度获取路由参数

Angular 使用延迟加载以角度获取路由参数,angular,angular-router,Angular,Angular Router,我将在Angular 5中从路由路径中检索一个参数 http://localhost:4200/#/dashboard/74618/LastCC 我将从route获得74618,这是一个id参数 我是这样处理的 constructor(public activatedRoute: ActivatedRoute) this.activatedRoute.paramMap.subscribe(params => { console.log("params******"); par

我将在Angular 5中从路由路径中检索一个参数

http://localhost:4200/#/dashboard/74618/LastCC
我将从route获得
74618
,这是一个
id
参数

我是这样处理的

constructor(public activatedRoute: ActivatedRoute)


this.activatedRoute.paramMap.subscribe(params => {
  console.log("params******");
  params.get("id");
});
我得到
未定义的
作为值

当我在这条路径上时,它正在工作
http://localhost:4200/#/dashboard/74618/
(无
\LastCC

LastCC是延迟加载的,以下是路由器配置:

const routes: Routes = [
  {
    path: "",
    component: CreditPointComponent
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class CreditPointRoutingModule {}
id参数位于父模块路由器配置(仪表板模块)上


您没有在
lastc
路由上配置参数。试着这样做:

  {
    path: ":id",
    component: DashboardComponent
  },
  {
     path: ":id/LastCC",
     loadChildren:
          "app/useful-documents/credit-point/credit-point.module#CreditPointModule"
   }
请注意,lastc路由的路径现在有一个路由参数:
path::id/LastCC“

还要注意,lastc路由不再是子路由。有必要吗

如果确实需要为子路由,则可能需要保留路由配置,并从父路由而不是从
lastc
路由读取参数

this.activatedRoute.parent.paramMap.subscribe(params => {
  console.log("params******");
  console.log(params.get("id"));
});

请注意
激活路由后的
.parent

您的路由器配置是什么样子的?请在配置路由的位置提供路由模块代码。我添加了新信息路由中没有参数我添加了父模块路由我应该从父模块读取是。你的第二个解决方案对角度5有效吗?是的。自Angular 4以来,布线没有太大变化。
this.activatedRoute.parent.paramMap.subscribe(params => {
  console.log("params******");
  console.log(params.get("id"));
});