I am building a angular application, everything was working fine till I imported and implemented the "Routing Module"
Error Message
I have gone through and don't think the following are possible problems:
Code for Router Module:
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{
}
Code for Root Component:
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 { }
You are exporting the wrong module. Change exports: [AppRoutingModule]
to exports: [RouterModule]
.
@NgModule({
imports: [
RouterModule.forRoot(appRoutes),
],
exports: [RouterModule]
})
export class AppRoutingModule {
}
Try to change:
exports: [AppRoutingModule]
to:
exports: [
RouterModule
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With