Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

Angular route parameter from parent cannot be retrieved

I have a strange issue where I have the following route setup:

const routes: Routes = [
  {
    path: '',
    component: CustomerControlPage,
    children: [
      {
        path: 'add',
        pathMatch: 'full',
        component: AddCustomerViewComponent
      },
      {
        path: 'edit/:id',
        component: EditCustomerViewComponent,
        children: [
          {
            path: 'user',
            component: CustomerAddUserViewComponent,
            children: [
              {
                path: 'select',
                component: CustomerAddUserSelectViewComponent,
                pathMatch: 'full'
              },
              {
                path: '',
                component: CustomerAddUserBaseViewComponent,
                pathMatch: 'full'
              }
            ]
          },
          {
            path: 'app',
            component: CustomerAddAppViewComponent,
            children: [
              {
                path: 'select',
                component: CustomerAddAppSelectViewComponent,
                pathMatch: 'full'
              },
              {
                path: '',
                component: CustomerAddAppBaseViewComponent,
                pathMatch: 'full'
              }
            ]
          },
          {
            path: '',
            component: CustomerEditBaseViewComponent,
            pathMatch: 'full' 
          }
        ]
      },
      {
        path: '',
        pathMatch: 'full',
        component: CustomerViewComponent
      }
    ]
  }
];

I can see at the component under the URL "edit/:id/user" can't retrieve the URL parameter 'id' from the parent component.

Normally I can get the URL parameter of the parent using the following code, in my case the parent paramMap is always null.

this.activatedRoute.parent.paramMap.subscribe(param => {
   console.log(param.get('id'))
});

If I want to read the parameter id using the following code I get a null object back:

this.activatedRoute.params.subscribe(param => {
   console.log(param.get('id'));
});

Am I missing something? Sorry for my bad english...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...