今天碰到空路由和空路由跳轉(zhuǎn)無(wú)效的坑,經(jīng)過(guò)折騰發(fā)現(xiàn)問(wèn)題础淤,發(fā)現(xiàn)原來(lái)是在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中導(dǎo)入了子路由)
@NgModule({
imports: [
? ?
AppRoutingModule,? ?
ApprovalModule,? ? ApprovalModule,
? ? AppRoutingModule
],
? ? bootstrap: [AppComponent]
})
export classAppModule { }