Is there a method to efficiently handle an unknown number of router parameters in a recursive manner?
For instance:
We are dealing with product categories that may have subcategories, which can have their own subcategories and so on. There are a few key criteria:
- If a category has no subcategories, we will redirect to
/categories/{id}/items
to display the list of items. - If a category has subcategories, it should be redirected to the next nested level like
/categories/{id}/{id}/.../{id}
which will display the subcategories list of the last categoryId. - Once we reach the final category without any subcategories, we will show the items list component at
./categories/{id}/{id}/.../{id}/items
The solution for handling this routing is to use a router resolver. But how can we effectively track these URLs in the routing module?
In my opinion, the routes should appear as follows:
{
path: '/categories/:id',
component: SubcategoriesListComponent
},
{
path: '/categories/:id/**/:id',
component: SubcategoriesListComponent,
},
{
path: '/categories/:id/**/:id/items',
component: CategoryItemsListComponent
}
Is it feasible to implement it in such a way?