Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: Unexpected module 'RouterModule' declared by the module 'AppRoutingModule'. Please add a @Pipe/@Directive/@Component annotation

Hello fellow programmer friends,

Need help for the error in the title.

This is my routing module code

app-routing.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

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

import { routes } from './routes';

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forRoot(routes)
  ],
  declarations: [RouterModule]
})
export class AppRoutingModule { }

I tried removing RouterModule from the declarations array as well but not getting rectified.

Please help.

like image 950
Manushi Avatar asked Nov 16 '25 18:11

Manushi


2 Answers

In declarations you can not add any Modules. As the error says: only Components,Pipes or Directives are allowed to be declared in declarations array

like image 59
Kostas Asargiotakis Avatar answered Nov 19 '25 10:11

Kostas Asargiotakis


Understood what mistake I did.

I placed the RouterModule in declarations instead of exports.

This thread may assist future learners who make the same mistake like me.

like image 20
Manushi Avatar answered Nov 19 '25 09:11

Manushi