文件
AppRoutingModule
包含:
const routes: Routes = [
{
path: "events",
component: EventComponent,
children: [
{
path: 'add',
component: AddEventComponent
}
]
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
我试图达到
AddEventComponent
通过URL:
localhost:4200/events/add
它没有打开,没有错误。
成分
添加事件组件
注册于
add-event.module.ts
:
import { NgModule } from "@angular/core";
import { SharedModule } from 'src/app/SharedModule';
import { CompanyService } from 'src/app/api/CompanyService';
import { AddEventComponent } from './add-event-component';
@NgModule({
imports: [SharedModule],
declarations: [AddEventComponent],
exports: [AddEventComponent],
providers: [CompanyService]
})
export class AddEventModule { }
然后
AddEventModule
已添加到主
AppModule
:
@NgModule({
declarations: [
],
imports: [
AddEventModule
]});
所以,我需要打开组件
添加事件组件
通过URL:
本地主机:4200/events/add
,现在它总是打开父级
EventComponent
附加模块
:
@NgModule({
declarations: [
AppComponent,
NofoundComponent
],
imports: [
CommonModule,
BrowserModule,
HttpClientModule,
SharedModule,
LoginModule,
LanguageModule,
EventModule,
AddEventModule,
VisitorModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: CustomTranslateLoader,
deps: [HttpClient]
}
}),
SocketIoModule.forRoot(config),
AppRoutingModule
],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: RequestInterception,
multi: true,
},
EventsService, VisitorsService, UserService, ExportService, AuthenticationGuard],
exports: [TranslateModule, AddEventModule],
bootstrap: [AppComponent]
})
export class AppModule { }