Angular 2辅助路线在2.1.0中如何工作? [英] Angular 2 how does auxiliary routes work in 2.1.0?

查看:57
本文介绍了Angular 2辅助路线在2.1.0中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这条路线:

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

dashboard的路由器如下所示:

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

在我的父视图(即/admin,仪表板路线为/admin/dashboard)中,我有一个<router-outlet name="admin"></router-outlet>,但是我似乎无法弄清楚它的语法,因为我得到了很多错误,每当我尝试.

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.

这是我尝试过的:

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

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

(路由器):

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

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

正确的方法是什么?

推荐答案

在父路由器中:

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

并选择/(admin:dashboard)

这篇关于Angular 2辅助路线在2.1.0中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆