首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角路由模块

角路由模块
EN

Stack Overflow用户
提问于 2020-02-04 16:12:06
回答 1查看 69关注 0票数 0

我尝试使用auth/page和app的不同模块(在每个components.html: auth/pages/app.html中)开发角8中的路由,我将路由器-outler放在了路由器-outler中,但在导航器控制台中出现了如下错误:

代码语言:javascript
复制
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 :

代码语言:javascript
复制
@NgModule({
    declarations: [
        AuthComponent,
        LoginComponent,
        RegisterComponent,
        ForgotPasswordComponent,
        ResetPasswordComponent
    ],
    exports: [

    ],
    imports: [
        FormsModule,
        CommonModule,
        AUTH_ROUTES
    ]
})
export class AuthModule { }

auth-routes.modules.ts

代码语言:javascript
复制
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

代码语言:javascript
复制
@NgModule({
    declarations: [
        AuthComponent,
        AllUsersComponent,
        AllUsersComponent,
        TestrouteComponent,
        PagesComponent
    ],
    exports: [

    ],
    imports: [
        BrowserModule,
        PAGES_ROUTES,
        AuthModule,
        CommonModule,
        RouterModule
    ]
})

pages.routes.ts

代码语言:javascript
复制
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

代码语言:javascript
复制
@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

代码语言:javascript
复制
const routes: Routes = [
  {
    path: '', component: PagesComponent, loadChildren: '../app/pages/pages.module.ts#PagesModule'
  },
];

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-04 16:36:23

AuthComponent文件中的声明数组中删除pages.module.ts。您还需要在AuthComponent中导出auth.module.ts,然后您就可以在pages.routes.ts文件中使用它了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60061408

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档