【问题标题】:how can i do angular routing to child to component我如何对子组件进行角度路由
【发布时间】:2020-06-21 12:46:03
【问题描述】:

我正在尝试导航到我的子定义组件,但我的路由器无法识别给定的路由。

路线如下:

在路由器文件中我定义了这样的内容:

const routes: Routes = [
{
    path: "",
    redirectTo: "products",
    component: StandardproductsComponent,
    pathMatch: "full",
    canActivate: [AuthorizedGuardService],
},
{
    path: "products",
    component: StandardproductsComponent,
    resolve: {
        loaded: StandardsResolver
    },
    children: [ 
        {
            path: ":productId/types",
            component: StandardtypesComponent,
            // resolve: {
            //     loaded: StandardTypesResolver
            // },
            // canActivate: [AuthorizedGuardService]
        }
    ]
}];

我无法这样做,任何人都可以帮助我解决这个问题,如何使我的路线可行。 我想要这样的路线:v3/products/{productId}/types

【问题讨论】:

  • 您的示例路由中的v3 是在哪里定义的?
  • 你在哪里

标签: angular typescript routing


【解决方案1】:

您有 2 条路线指向相同的名称和相同的组件

尝试执行以下操作

const routes: Routes = [
    {
        path: "",
        redirectTo: "products",
        pathMatch: 'full'
    },
    {
        path: "products",
        component: StandardproductsComponent,
        resolve: {
            loaded: StandardsResolver
        },
        children: [
            {
                path: ":productId/types",
                component: StandardtypesComponent,
            }
        ]
    }
];

当然,StandardproductsComponent 必须有

<router-outlet></<router-outlet>

希望这会有所帮助!

【讨论】:

  • 谢谢,但我错过了我不应该将 (standardtypescomponent) 作为子组件,因为我不希望 standardproductscomponent 与其他组件一起存在,因此我使用常规路由而不是子路由。
猜你喜欢
  • 1970-01-01
  • 2017-06-13
  • 2018-05-17
  • 2022-10-14
  • 2019-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-28
相关资源
最近更新 更多