Angular 2 rc5 router match X subcategories

心不动则不痛 提交于 2019-12-11 05:09:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!