【问题标题】:Using one component for parent and child routes为父子路由使用一个组件
【发布时间】:2017-12-14 01:10:32
【问题描述】:

我创建了一个延迟加载模块,当用户重定向到路由时必须加载一个组件但是我收到如下所述的错误:

Error: Uncaught (in promise): Error: Cannot find primary outlet to load 'XYZComponent'

这是我的模块。

import { XYZComponent } from './xyz-confirm'

const XYZConfirmRoute: Route[] = [
  { 
    path: '', component: XYZComponent ,
    children: [
        { path: 'test', component: XYZComponent}
    ]
  }
];

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    RouterModule.forChild(XYZConfirmRoute)
  ],
  declarations: [XYZComponent],
  exports: [RouterModule],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA ]  
})
export class XYZConfirmModule { }

正如您在上面看到的,我想为父路由和子路由加载XYZComponent。有什么办法可以做到吗?

【问题讨论】:

标签: angular typescript routes components angular2-routing


【解决方案1】:

你不能简单地这样做

  {
    path: 'test', component: XYZComponent
  },{
    path: '', component: XYZComponent
  }

注意你必须像我一样在顶部定义窄路径test在顶部然后''强>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-19
    • 2016-09-04
    • 2016-08-21
    • 2021-05-31
    • 1970-01-01
    • 2017-09-16
    • 2016-12-19
    • 2018-12-19
    相关资源
    最近更新 更多