如何在使用名称 router-outlet 时创建自定义 url?

问题描述 投票:0回答:1

我不想要这个(

sidebar:cart-page
)请帮助我吗?

我想让内部购物车组件在基于标签的搜索时变得通用,但也不希望(

sidebar:cart-page
)

angular url-routing named-routing
1个回答
0
投票

这是不可能的。 Angular 需要知道应该使用哪个

router-outlet
。一种方法是使用
child-routes
。那么主组件中就只有自己的
router-outlet
,每个子组件也有一个
router-outlet

示例

const routes: Routes = [
  {
    path: 'first-component',
    component: FirstComponent, // this is the component with the <router-outlet> in the template
    children: [
      {
        path: 'child-a', // child route path
        component: ChildAComponent, // child route component that the router renders
      },
      {
        path: 'child-b',
        component: ChildBComponent, // another child route component that the router renders
      },
    ],
  },
];

孩子可以生孩子,两个。所以你的路线看起来不同,而且没有

(sidebar:cart-page)

© www.soinside.com 2019 - 2024. All rights reserved.