0

I am getting this error when I am trying to add RouterModule.forRoot(appRoutes) line in my app.module.ts. Below are my app.module.ts file

app.module.ts file.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {RouterModule} from '';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { AboutComponent } from './about/about.component';
import { CoursesComponent } from './courses/courses.component';
import {FormsModule} from '@angular/forms';
import {RouterModule, Routes} from '@angular/router';

const appRoutes: Routes = [
 {path:'',component:HeaderComponent},
 {path:'about',component:AboutComponent},
 {path:'courses',component:CoursesComponent}
];

@NgModule({
  declarations: [
  AppComponent,
  HeaderComponent,
  AboutComponent,
  CoursesComponent
 ],
imports: [
  BrowserModule,
  FormsModule,
  RouterModule.forRoot(appRoutes)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

1 Answer 1

1

Reason of this error is in your imports of RouterModule you didn't specify the path of this module. take a look at your imports.

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

import {RouterModule} from '';

import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { AboutComponent } from './about/about.component';
import { CoursesComponent } from './courses/courses.component';
import {FormsModule} from '@angular/forms';
import {RouterModule, Routes} from '@angular/router';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.