【发布时间】:2018-01-31 08:58:00
【问题描述】:
所以我正在做一个小项目来建立一个网上商店。 但我真的很难解决这部分路由问题。
这是我的路由代码:
{ path: 'productrange', component: ProductRangeComponent },
{ path: 'productrange/:productgroup', component: ProductRangeComponent },
{ path: 'productrange/:productgroup/:producttype', component: ProductRangeComponent },
{ path: 'products/:productgroup/:producttype', component: ProductsComponent },
{ path: 'products/:productgroup/:producttype/:productsubtype', component: ProductsComponent },
所以这行得通,但我认为这不是最好的方法。因为我使用了两个不同的组件和两个不同的路径。
这就是我想要的:
{ path: 'products', component: ProductsComponent },
{ path: 'products/:productgroup', component: ProductsComponent },
{ path: 'products/:productgroup/:producttype', component: ProductsComponent },
{ path: 'products/:productgroup/:producttype/:productsubtype', component: ProductsComponent },
只要产品仅在最后一个路径中开始显示,这将起作用,但情况并非总是如此。有时在第 3 条路径甚至第 2 条路径中可能会有产品。但是我不知道如何让系统知道应该有产品展示。
当然,我可以多次调用数据库,检查是否有更多类别,如果没有,则搜索产品并从那里开始。但我不认为这是正确的方法,因为这意味着对服务器和数据库的不必要调用。
谢谢!
【问题讨论】:
标签: html angularjs angular routing