我尝试使用auth/page和app的不同模块(在每个components.html: auth/pages/app.html中)开发角8中的路由,我将路由器-outler放在了路由器-outler中,但在导航器控制台中出现了如下错误:
compiler.js:2175 Uncaught Error: Type AuthComponent is part of the declarations of 2 modules:
AuthModule and PagesModule! Please consider moving AuthComponent to a higher module that
imports AuthModule and PagesModule. You can also create a new NgModule that exports and
includes AuthComponent then import that NgModule in AuthModule and PagesModule.auth.module.ts :
@NgModule({
declarations: [
AuthComponent,
LoginComponent,
RegisterComponent,
ForgotPasswordComponent,
ResetPasswordComponent
],
exports: [
],
imports: [
FormsModule,
CommonModule,
AUTH_ROUTES
]
})
export class AuthModule { }auth-routes.modules.ts
const authRoutes: Routes = [
{
path: "login", component: LoginComponent, data: { title: "Login" }
},
{
path: "register", component: RegisterComponent, data: { title: "Register" }
},
{
path: "forgot/password", component: ForgotPasswordComponent, data: { title: "Forgot Password" }
},
{
path: "reset/password", component: ResetPasswordComponent, data: { title: "Reset Password" }
}
];
export const AUTH_ROUTES = RouterModule.forChild(authRoutes);pages.module.ts
@NgModule({
declarations: [
AuthComponent,
AllUsersComponent,
AllUsersComponent,
TestrouteComponent,
PagesComponent
],
exports: [
],
imports: [
BrowserModule,
PAGES_ROUTES,
AuthModule,
CommonModule,
RouterModule
]
})pages.routes.ts
const pagesRoutes: Routes = [
{
path: "users", component: AllUsersComponent, data: { title: "Users" }
},
{
path: "orders", component: AllOrdersComponent, data: { title: "Orders" }
},
{
path: "protect", component: TestrouteComponent, data: { title: "Protect" }, canActivate: [AuthGuard]
},
{
path: '', component: AuthComponent, loadChildren: '../pages/auth/auth.module.ts#AuthModule'
},
];
export const PAGES_ROUTES = RouterModule.forChild(pagesRoutes);app.module.ts
@NgModule({
declarations: [
AppComponent,
PagesComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ReactiveFormsModule,
FormsModule,
HttpClientModule,
PagesModule,
ServiceModule
],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: JwtInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: ErrorInterceptor,
multi: true
}
],
bootstrap: [AppComponent]
})
export class AppModule { }app-routing.module.ts
const routes: Routes = [
{
path: '', component: PagesComponent, loadChildren: '../app/pages/pages.module.ts#PagesModule'
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }发布于 2020-02-04 16:36:23
从AuthComponent文件中的声明数组中删除pages.module.ts。您还需要在AuthComponent中导出auth.module.ts,然后您就可以在pages.routes.ts文件中使用它了。
https://stackoverflow.com/questions/60061408
复制相似问题