Angular 2 how does auxiliary routes work in 2.1.0?

佐手、 提交于 2020-02-08 04:21:07

问题


I have this route:

{
   path: 'dashboard',
   loadChildren: '../pages/dashboard/dashboard.module#DashboardModule'
}

With the dashboard's router looking like this:

@NgModule({
  imports: [
    ComponentsModule,
    SharedModule,
    RouterModule.forChild([
      {
        path: '',
        component: DashboardComponent
      }
    ])
  ],
  declarations: [
    DashboardComponent
  ]
})
export class DashboardRouterModule {}

And in my parent view (which is /admin, dashboard route is /admin/dashboard), I have a <router-outlet name="admin"></router-outlet>, but I can't seem to figure out the syntax for this because I just get a bunch of errors whenever I try.

Here's what I tried:

{
   path: 'dashboard(admin: '')',
   loadChildren: '../pages/dashboard/dashboard.module#DashboardModule'
}

{
   path: 'dashboard(admin: dashboard)',
   loadChildren: '../pages/dashboard/dashboard.module#DashboardModule'
}

(router):

 {
   path: '(dashboard: '')',
   component: DashboardComponent
 }

 {
   path: '',
   component: DashboardComponent,
   outlet: 'admin'
 }

What is the correct way?


回答1:


In the parent router:

{
   path: 'dashboard',
   loadChildren: '../pages/dashboard/dashboard.module#DashboardModule',
   outlet: 'admin'
}

and go with /(admin:dashboard)



来源:https://stackoverflow.com/questions/40124618/angular-2-how-does-auxiliary-routes-work-in-2-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!