错误:“ AppRoutingModule”模块无法自行导入

时间:2019-12-19 22:14:20

标签: angular routing angular-ui-router

任何帮助或提示将不胜感激!! 我正在关注有关路由的角度文档:tracking issue for the mentioned RFC 我已经到达里程碑2的终点:路由模块。

这是我的angular-router-sample \ src \ app \ app-routing.module.ts:

                import { NgModule } from '@angular/core';
            import { RouterModule, Routes } from '@angular/router';

            import { CrisisListComponent } from './crisis-list/crisis-list.component';
            import { HeroListComponent } from './hero-list/hero-list.component';
            import { PageNotFoundComponent } from './page-not-found/page-not-found.component';



            const appRoutes: Routes = [
              { path: 'crisis-center', component: CrisisListComponent },
              { path: 'heroes', component: HeroListComponent },
              { path: '', redirectTo: '/heroes', pathMatch: 'full' },
              { path: '**', component: PageNotFoundComponent}
            ];

            @NgModule({
              declarations: [],
              imports: [
                RouterModule.forRoot(
                  appRoutes,
                  { enableTracing: true } // <--debugging purposes only
                ),
                AppRoutingModule
              ],
              exports: [
                RouterModule
              ]
            })
            export class AppRoutingModule { }

这是我的angular-router-sample \ src \ app \ app.module.ts:

                import { NgModule } from '@angular/core';
            import { BrowserModule } from '@angular/platform-browser';
            import { FormsModule } from '@angular/forms';

            import { AppComponent } from './app.component';
            import { AppRoutingModule } from './app-routing.module';



            import { CrisisListComponent } from './crisis-list/crisis-list.component';
            import { HeroListComponent } from './hero-list/hero-list.component';
            import { PageNotFoundComponent } from './page-not-found/page-not-found.component';


            @NgModule({
              declarations: [
                AppComponent,
                CrisisListComponent,
                HeroListComponent,
                PageNotFoundComponent
              ],
              imports: [
                BrowserModule,
                FormsModule,
                AppRoutingModule,
              //  AppRoutingModule


              ],
              providers: [],
              bootstrap: [AppComponent]
            })
            export class AppModule { }

这是我的控制台日志错误:

https://angular.io/guide/router

1 个答案:

答案 0 :(得分:1)

在您的第一个代码段(应用程序路由模块)中,您具有:

     imports: [RouterModule.forRoot(appRoutes,{ enableTracing: true }),
         AppRoutingModule]
})

从import子句中删除AppRoutingModule。如错误消息所示,路由模块无法导入自身