Angular 2 rc5路由器匹配X子类别 [英] Angular 2 rc5 router match X subcategories
问题描述
在Angular 2 rc5中使用新路由器,并具有一条通用路由,我不确定该如何写.
Using the new router in Angular 2 rc5 and have a common route I'm unsure how to write.
我需要一个类似以下内容的网址:
I need an url that's something like:
http://localhost:3000/store/ {类别}/{产品名称}
http://localhost:3000/store/{category}/{product-name}
这似乎很简单,直到我添加,我一直在寻找可能存在多个子类别,例如(我们不知道可能有多少个子类别):
This seems simple enough until I add in that I'm looking for there to be potentially multiple sub categories like (without us knowing how many there possibly are):
http://localhost:3000/store/ {类别1}/{子类别2}/{子类别3}..../{产品名称}
http://localhost:3000/store/{category 1}/{sub category 2}/{sub category 3}..../{product-name}
如何创建与子类别和产品都匹配的路径.除了"full"以外,还有其他使用pathMatch的东西吗?
How can i create a path that matches against both the sub categories and the product. Is it something using pathMatch somehow other than "full"?
const appRoutes: Routes = [
{
path: '/store/:cat',
component: CategoryComponent
},
{
path: '/store/:cat/:product',
component: ProductComponent
}
];
推荐答案
尝试以下代码:
const appRoutes: Routes = [
{
path: 'store',
component: StoreHomeComponent,
children: [
{
path: '**',
component: ProductComponent
}]
}];
StoreHomeComponent:
StoreHomeComponent:
@Component({
template: '<router-outlet></router-outlet>'
})
export class StoreHomeComponent {}
此代码也未经测试,但应该可以工作
This code is not tested either, but it should work
这篇关于Angular 2 rc5路由器匹配X子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!