【发布时间】:2016-09-28 16:00:33
【问题描述】:
我想实现类似/products 显示所有产品,/products/:category 显示与特定类别相关的所有产品。为了实现这一点,我有以下路线:
const productsRoutes: Routes = [
{
path: 'products',
component: ProductsComponent,
children: [
{
path: '',
component: ProductsListComponent,
},
{
path: ':category',
component: ProductsListComponent
}
]
}
];
问题
当我在类别之间切换时,一切都很好,当我在所有产品和类别产品之间切换时,反之亦然,Angular 重新绘制组件并出现闪烁。
据我所知,Angular 2 Router 最终版本没有 Regex。有什么我遗漏的,还是目前这是唯一的解决方案?
【问题讨论】:
-
对于这种情况,我能找到的最接近的是这里:stackoverflow.com/questions/41899090/…这里有一种类似的情况:stackoverflow.com/a/41931088/2911817
-
您可以使用路径匹配器函数而不是指定静态路径来执行此操作:请参阅 angular.io/guide/routing-with-urlmatcher 和 stackoverflow.com/a/56391974/1751497