Different routes same component

后端 未结 4 1478
眼角桃花
眼角桃花 2021-01-01 12:06

I want to achieve something like this /products shows all the products and /products/:category shows all the products related to a specific categor

4条回答
  •  忘掉有多难
    2021-01-01 12:34

    You can solve it by using redirect,

    const productsRoutes: Routes = [
      {
        path: 'products',
        component: ProductsComponent,
        children: [
            {
                // path => '/products'
                path: '',
                redirectTo: ':category',
            },
            {
                // path => '/products/:category'
                path: ':category',
                component: ProductsListComponent
            }
        ]
      }
    ];
    

    It's more like set one path default, unless there is a matching path.

提交回复
热议问题