Angular2空路由和空路由跳转无效的坑

今天碰到空路由和空路由跳转无效的坑,经过折腾发现问题,发现原来是在app.module中需要先引入子路由,再引入根路由,代码:

根路由:

constroutes: Routes = [{

path:'',

redirectTo:'approval',

pathMatch:'full',

},{

path:'approval',

component: ApprovalComponent

}];

子路由:

constroutes: Routes = [{

path:'approval',

component: ApprovalComponent,

children: [{

        path:'',

        redirectTo:'list',

        pathMatch:'full'

    },{

        path:'list',

        component: ApprovalListComponent

    }]

}];

AppModule.ts  (ApprovalModule中导入了子路由)

@NgModule({

imports: [

    AppRoutingModule,

    ApprovalModule,

    ApprovalModule,

    AppRoutingModule

],

    bootstrap: [AppComponent]

})

export classAppModule { }

你可能感兴趣的:(Angular2空路由和空路由跳转无效的坑)