How to route to a Module as a child of a Module - Angular 2 RC 5

前端 未结 7 1200
暖寄归人
暖寄归人 2020-12-04 07:43

I am in the process upgrading an application I\'m working on to the latest Angular 2 release candidate. As part of this work I am attempting to use the NgModule spec and mig

7条回答
  •  温柔的废话
    2020-12-04 08:09

    When you are using ngModules and RC5, the routing configuration of your parent module does not need to know anything about the child modules routing. You only have to define the routes for your parent module here. Furthermore you have to import the child module into your parent module. In the child module you have to define your routes this way:

    export const childRoutes: Routes = [
      {
        path: 'someChild',
          component: SomeChildComponent,
          children: [
            { path: '', component: SomeChildSubComponent1 },
            { path: 'comp1', component: SomeChildSubComponent1 },
            { path: 'comp2', component: SomeChildSubComponent2 }
          ]
      }
    ];
    

    This will let you have a url like /someParent/someChild/comp1 - and the components are displayed in their corresponding router-outlet. Please note: You HAVE TO declace a component for the empty path. Otherwise you are not able to navigate to you children.

提交回复
热议问题