How to handle angular 5 recursive unknown exact number router parameters?

后端 未结 1 1687
离开以前
离开以前 2021-01-18 08:35

Is there a way to handle recursively unknown exact number of router parameters?

For example:

We have products categories, which can have su

相关标签:
1条回答
  • 2021-01-18 09:18

    Possible solution with componentless routes: in routes config

    {
        path: 'categories/:id', children: [
        {path: '**', component: SubcategoriesListComponent}
    ]
    }
    

    in component file:

    export class SubcategoriesListComponent {
    
      constructor(aroute: ActivatedRoute) {
        aroute.url.subscribe((data) => {
          console.log('params ', data); //contains all the segments so put logic here of determining what to do according to nesting depth
        });
    
      }
    
    }
    

    Here is the output example (i tested on my project ErrorComponent so don't be confused)

    0 讨论(0)
提交回复
热议问题