组件是两个模块声明的一部分:AppRoutingModule和AppModule

Aak*_*kur 5 routing components module angular

我试图通过在自己的打字稿文件中定义路由模块来将其与其他模块分开.但是我得到了上面的错误:Component是两个模块声明的一部分:AppRoutingModule和AppModule

共享以下两个模块:

AppRoutingModule

import { NgModule } from '@angular/core'
import { RouterModule, Routes } from '@angular/router'
import { AdminHomeComponent } from './nav/adminhome.component'
import { UserHomeComponent } from './nav/userhome.component'
import { ContactComponent } from './nav/contact.component'
import { LandingComponent } from './nav/mainhome.component'
import { LoginFormComponent } from './nav/login.component'


const appRoutes: Routes = [
    { path: 'login', component: LoginFormComponent },
    { path: 'adminHome', component: AdminHomeComponent },
    { path: 'userHome', component: UserHomeComponent },
    { path: 'contact', component: ContactComponent },
    { path: '', component: LandingComponent }
];


@NgModule({
    imports: [
        RouterModule.forRoot(appRoutes)
    ],
    exports: [
        RouterModule
    ]
})
export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)

的AppModule

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HttpModule } from '@angular/http';
import { AppRoutingModule} from './app.routing'

import { AdminHomeComponent } from './nav/adminhome.component'
import { UserHomeComponent } from './nav/userhome.component'
import { ContactComponent } from './nav/contact.component'
import { LandingComponent } from './nav/mainhome.component'
import { LoginFormComponent } from './nav/login.component'
import { ShareService } from './nav/ShareService'
//import { PaginationModule } from 'ng2-bootstrap';
//import { Ng2PaginationModule } from 'ng2-pagination';

@NgModule({
    imports: [BrowserModule, FormsModule, HttpModule, AppRoutingModule ],
    declarations: [AppComponent, AdminHomeComponent, UserHomeComponent, ContactComponent, LandingComponent, LoginFormComponent],
    bootstrap: [AppComponent],
    providers: [ShareService]

})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

我按照https://angular.io/docs/ts/latest/guide/router.html路由文档进行了操作,但是遇到了这样的错误.

有人可以看看代码中是否存在某些错误.谢谢.

Gün*_*uer 1

我认为您应该将out 中AdminHomeComponent引用的所有其他组件移至不同的模块中,并将此模块添加到of中。AppRoutingModuleAppModuleimportsAppRoutingModule