错误:模块“ AppRoutingModule”以递归方式导出了模块“ AppRoutingModule”

时间:2019-02-20 14:44:41

标签: angular angular-routing angular-router

我正在构建一个有角度的应用程序,直到我导入并实现了“路由模块”,一切工作都很好。

错误消息

enter image description here

我已经经历了,不认为以下是可能的问题:

  • 语法错误,例如多个逗号等
  • 递归调用

路由器模块代码:

import { NgModule } from '@angular/core';
import { Routes , RouterModule } from '@angular/router';
import { RecipesComponent } from './recipes/recipes.component';
import { ShoppingListComponent } from './shopping-list/shopping-list.component';

const appRoutes: Routes = [
	{path: 'recipes', component: RecipesComponent},
	{path: 'shopping-list', component: ShoppingListComponent},
  	{ path: '', redirectTo: 'recipes', pathMatch: 'full'},
  	{ path: '**', redirectTo: '/not-found'},
]

@NgModule({
	imports: [
		RouterModule.forRoot(appRoutes),
	],
	exports: [AppRoutingModule]
})

export class AppRoutingModule{

}

根组件代码:

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

import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { RecipesComponent } from './recipes/recipes.component';
import { RecipeListComponent } from './recipes/recipe-list/recipe-list.component';
import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component';
import { RecipeItemComponent } from './recipes/recipe-list/recipe-item/recipe-item.component';
import { ShoppingListComponent } from './shopping-list/shopping-list.component';
import { ShoppingEditComponent } from './shopping-list/shopping-edit/shopping-edit.component';
import { DropdownDirective } from './shared/dropdown.directive';
import { ShoppingListService } from './shopping-list/shopping-list.service';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
    RecipesComponent,
    RecipeListComponent,
    RecipeDetailComponent,
    RecipeItemComponent,
    ShoppingListComponent,
    ShoppingEditComponent,
    DropdownDirective
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    AppRoutingModule
  ],
  providers: [ShoppingListService],
  bootstrap: [AppComponent]
})
export class AppModule { }

3 个答案:

答案 0 :(得分:2)

您导出的模块错误。将exports: [AppRoutingModule]更改为exports: [RouterModule]

@NgModule({
    imports: [
        RouterModule.forRoot(appRoutes),
    ],
    exports: [RouterModule]
})
export class AppRoutingModule {
}

答案 1 :(得分:1)

尝试更改:

exports: [AppRoutingModule]

收件人:

exports: [
    RouterModule
  ]

答案 2 :(得分:0)

导出RouterModule而不是AppRoutingModule。

exports: [RouterModule]