每当我申请“孩子”时属性,它给出了“无法找到路由”的错误。虽然它们写得很好。
以下是错误的屏幕截图:
以下是代码:
app.module.ts
import {NgModule} from '@angular/core';
import {BrowserModule } from '@angular/platform-browser';
import {Http, HttpModule} from '@angular/http';
import { FormsModule } from '@angular/forms';
import { Router,RouterModule } from '@angular/router';
import {AppComponent} from "./app.component";
import {ComponentsComponent} from "./app/components/components.component";
import {TrainingComponent} from "./app/training/training.component";
import {ComponentsModule} from "./app/components/components.module";
import {TrainingModule} from "./app/training/training.module";
import {DemoHelloWorldComponent} from './app/training/helloWorld/demoHelloWorld.component';
import {HelloWorldComponent} from "./app/training/helloWorld/helloWorld.component"
import {CompositeComponentComponent} from './app/training/compositeComponent/compositeComponent.component';
import {TrainingComponentComponent} from './app/training/trainingComponent/trainingComponent.component';
import {TrainingModuleComponent} from './app/training/trainingModule/trainingModule.component';
import {RestServiceProviderComponent} from './app/training/restServiceProvider/restServiceProvider.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
ComponentsModule,
TrainingModule,
RouterModule.forRoot([
{
path: 'training',
component:TrainingComponent,
children:[
{
path: 'hello-world',
component:HelloWorldComponent
},
{
path: 'training-component',
component:TrainingComponentComponent
},
{
path: 'training-module',
component:TrainingModuleComponent
},
{
path: 'composite-components',
component:CompositeComponentComponent
},
{
path: 'rest-service-provider',
component:RestServiceProviderComponent
}
]
},
{
path: 'demo-components',
component:ComponentsComponent,
}
]),
],
declarations:
[
AppComponent,
ComponentsComponent,
TrainingComponent,
HelloWorldComponent,
CompositeComponentComponent,
TrainingComponentComponent,
TrainingModuleComponent,
RestServiceProviderComponent,
DemoHelloWorldComponent
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
// Diagnostic only: inspect router configuration
constructor(router: Router) { }
}
答案 0 :(得分:0)
尝试添加默认路线进行培训,因为我认为这是必要的。
path: 'training',
children:[
{
path: '',
component: TrainingComponent
}
(...)