我创建了具有较深子路径的路径。我添加<router-outlet>
了包裹在NgModule中的AdminComponent组件。但是刷新页面后出现此错误:
'router-outlet' is not a known element
可能是因为我忘记将某些模块导入admin.module.ts
请帮忙。谢谢。
app.routes.ts
export const routes: Routes = [
{
path: '',
component: AppComponent,
children: [
{
path: '',
component: LoginComponent
},
{
path: 'admin',
component: AdminComponent
},
{
path: 'user',
component: UserComponent
},
{
path: 'there',
component: ThereComponent
}
]
}
]
app.module.ts
@NgModule({
imports: [
BrowserModule,
AppRoutes,
FormsModule,
ReactiveFormsModule,
HttpModule,
RouterModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (http: Http) => {
return new TranslateStaticLoader(http, './src/assets/i18n', '.json')
},
deps: [Http]
}),
UserComponentModule,
AdminComponentModule,
LoginComponentModule,
ThereComponentModule,
DashboardComponentModule
],
declarations: [
AppComponent
],
providers: [
FormBuilder
],
bootstrap: [AppComponent]
})
admin.component.ts和admin.module.ts
// admin.component.ts
import {Component} from "@angular/core";
@Component({
selector: 'admin',
template: "<router-outlet></router-outlet>",
})
export class AdminComponent {
constructor() {
}
}
// admin.module.ts
const ADMIN_DECLARATION = [
AdminComponent
];
@NgModule({
imports: [
BrowserModule,
TranslateModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
ADMIN_DECLARATION
],
exports: [
ADMIN_DECLARATION
],
providers: [
TranslateService,
FormBuilder
]
})
export class AdminComponentModule {
}
;