【发布时间】:2018-01-24 15:59:31
【问题描述】:
在我的应用中,每个用户都可以访问类别和子类别树中的一堆“项目”。这棵树可以是任何深度并且是动态生成的。我可以查询它,但我想避免这样做,因为我只想根据这样的 url 在路由器插座中显示“ItemComponent”:
localhost:4200/items/cat_a/sub_a/item_x
localhost:4200/items/cat_a/sub_a/sub_sub_a/item_y
localhost:4200/items/cat_b/item_z
最好我想通过匹配以“items/”开头的任何路径并自己在“ItemComponent”中解析其余路径来做到这一点,但我能够让它工作的唯一方法是这样的:
{ path: 'items/:a', component: ItemComponent }
{ path: 'items/:a/:b', component: ItemComponent }
{ path: 'items/:a/:b/:c', component: ItemComponent }
{ path: 'items/:a/:b/:c/:d', component: ItemComponent }
{ path: 'items/:a/:b/:c/:d/:e', component: ItemComponent }
...
...
然而,这似乎有点愚蠢,如果有一条路径比我选择在这里停下来的地方更深一层,我显然就有麻烦了。我该如何改进呢?
【问题讨论】:
标签: angular angular-routing angular5 angular-router