Angular 角度11所有页面转到404

Angular 角度11所有页面转到404,angular,angular-ui-router,Angular,Angular Ui Router,我在我的新项目中使用Angular,它有3个模块,因此我决定将其分为3个模块。这是我的应用程序路由模块 const routes: Routes = [ { path: '', component: LayoutDefaultComponent, pathMatch: 'full', children: [ { path: '', component: OverviewComponent }, ] }, // 404 Not Found page {

我在我的新项目中使用Angular,它有3个模块,因此我决定将其分为3个模块。这是我的应用程序路由模块

const routes: Routes = [
  {
    path: '', component: LayoutDefaultComponent, pathMatch: 'full', children: [
      { path: '', component: OverviewComponent },
    ]
  },
  // 404 Not Found page
  { path: '**', component: NotFoundComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
这很好用。之后,我创建了另一个模块及其单独的路由,如下所示

const routes: Routes = [
  { 
    path: 'user',
    component: LayoutDefaultComponent,
    pathMatch: 'full',
    children: [
      { path: '', component: UserOverviewComponen},
    ],
  },
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class CloudRoutingModule { }
这是用户路由模块,导入到用户模块中,如下所示

const routes: Routes = [
  { 
    path: 'user',
    component: LayoutDefaultComponent,
    pathMatch: 'full',
    children: [
      { path: '', component: UserOverviewComponen},
    ],
  },
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class CloudRoutingModule { }
这是我的用户模块

  imports: [
    CommonModule,
    UserRoutingModule,
    SharedModule
  ],
这是我的app.module.ts文件

@NgModule({
  declarations: [
    AppComponent,
    NotFoundComponent,
    // Pages
    OverviewComponent,
    HelpCenterComponent,
    ChangelogComponent,
  ],

  imports: [
    BrowserModule,
    HttpClientModule,
    NgbModule,
    FlexLayoutModule,
    Ng2ChartsModule,
    PerfectScrollbarModule,
    NgxDatatableModule,
    TagInputModule,
    TranslateModule.forRoot({
      loader: {
          provide: TranslateLoader,
          useFactory: HttpLoaderFactory,
          deps: [HttpClient]
      }
    }),
    // App
    AppRoutingModule,
    LayoutModule,
    // Auth Module
    AuthModule,
    // Apps
    UserModule
  ],
  providers: [
    Title,
    AppService,
    {
      provide: HTTP_INTERCEPTORS,
      useClass: AuthInterceptorService,
      multi: true
    }
  ],
  bootstrap: [
    AppComponent
  ]
})
export class AppModule {}
但是如果我点击自动重定向到404页面的用户链接。我找不到问题所在。有人能帮忙解决这个问题吗


提前感谢

这是因为路由模块导入顺序错误。将
批准模块
放在底部

<代码>布局模块, //验证模块 AuthModule, //应用程序 用户模块, 批准模块 如果将
AppRoutingModule
置于任何其他模块之上,而该模块包含此行:

{路径:'**',组件:NotFoundComponent}
当这个路由匹配时,Angular router不会查看任何其他路由,正如您可以猜到的,它将始终匹配url


您可以在此处找到的文档中有一个章节对此进行了说明:

您的路由使用相同的路由调用两个组件,可以吗?你是如何定义两个模块之间的全局路由的?你能在你的问题中添加app-routing.module吗?@GabrielSereno你的意思是LayoutDefaultComponent吗?@RebaiAhmed我已经在app-ModuleAnks中导入了用户模块。它按预期工作