问题
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/{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/{category 1}/{sub category 2}/{sub category 3}..../{product-name}
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"?
standard app.routing.ts
const appRoutes: Routes = [
{
path: '/store/:cat',
component: CategoryComponent
},
{
path: '/store/:cat/:product',
component: ProductComponent
}
];
回答1:
try below code:
const appRoutes: Routes = [
{
path: 'store',
component: StoreHomeComponent,
children: [
{
path: '**',
component: ProductComponent
}]
}];
StoreHomeComponent:
@Component({
template: '<router-outlet></router-outlet>'
})
export class StoreHomeComponent {}
This code is not tested either, but it should work
来源:https://stackoverflow.com/questions/39149927/angular-2-rc5-router-match-x-subcategories