我有一個按鈕與一個延遲加載模塊的routerLink指令。但鏈接不起作用。當它被加載到瀏覽器地址欄中(當點擊按鈕時)組件永遠不會被加載,並且在控制檯中我得到一個404錯誤。我究竟做錯了什麼。Angular 4按鈕鏈接到LazyLoading模塊路由不工作
我想要實現的功能是:當我去/事件/ 5獲取填充表單(來自ID = 5的事件編輯/更新),而當我去/事件/新獲得一個空形式插入新的事件。
我想這個問題可能在IncidentsRoutingModule中,但是我無法工作。
我的主要應用路由模塊如下:
const appRoutes: Routes = [
{ path: '', redirectTo:'home', pathMatch:'full'},
{ path: 'home', component: HomeComponent },
{ path: 'incidents', loadChildren : 'app/incidents/incidents.module#IncidentsModule' },
{ path: 'patients', loadChildren: 'app/patients/patients.module#PatientsModule' },
{ path: 'doctors', loadChildren: 'app/doctors/doctors.module#DoctorsModule' },
{ path: 'clinics', loadChildren: 'app/clinics/clinics.module#ClinicsModule' },
{ path: 'search', component: SearchComponent },
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule {}
的IncidentsModule是:
@NgModule({
imports: [
CommonModule,
FormsModule,
IncidentsRoutingModule
],
declarations: [
IncidentsComponent,
IncidentDetailsComponent,
IncidentsListComponent
],
providers:[IncidentsService]
})
export class IncidentsModule { }
的IncidentsRoutingModule是:
const incidentsModuleRoutes: Routes = [
{
path: '',
component: IncidentsComponent,
children: [
{
path: '', component: IncidentsListComponent,
children: [
{
path:':id', component: IncidentDetailsComponent
},
{
path: 'new', component: IncidentDetailsComponent
}
]
}
]
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(incidentsModuleRoutes)
],
exports: [RouterModule]
})
export class IncidentsRoutingModule { }
我IncidentsComponent具有帶有按鈕一個不起作用的routerLink指令。貝婁是我IncidentsComponent:
@Component({
// selector: 'app-incidents',
template: `
<div class="container-fluid">
<h3 style="margin:20px 20px 0px 20px;">Περιστατικά</h3>
<button type="button" class="btn btn-outline-primary" style="margin: 20px" routerLink="/incidents/new">
<i class="fa fa-plus-circle" style="margin-right: 10px"></i>
Νέο Περιστατικό
</button>
<router-outlet></router-outlet>
</div>
`,
styleUrls: ['./incidents.component.css']
})
export class IncidentsComponent {
constructor() {
}
}
你是什麼意思不工作?得到錯誤? –
是404找不到 – mixtou