typescript Angular 14 -路由模块问题-路由配置无效

a64a0gku  于 2023-03-04  发布在  TypeScript
关注(0)|答案(2)|浏览(289)

从Angular 13升级到Angular 14后,Angular 布线出现问题。出现以下错误:

*Uncaught Error: Uncaught (in promise): Error: NG04014: Invalid configuration of route 'homepage/'. One of the following must be provided: component, loadComponent, redirectTo, children or loadChildren*

App.routing.ts

export const routes: Routes = [
  { path: '', redirectTo: 'homepage', pathMatch: 'full'},
  {
    path: 'homepage',
    loadChildren: () =>
      import('src/app/homepage/homepage-component/homepage.module').then(m => m.HomepageModule),
    canActivate: [AuthGuard]
  },
  {
    path: 'sales',
    loadChildren: () =>
      import('src/app/reports/sales-component/sales.module').then(m => m.HomepageModule),
    canActivate: [AuthGuard]
  },

我试过添加组件,加载组件等到路径中,但是加载子项不能正常工作。我用的加载子项是不是错了?

wz3gfoph

wz3gfoph1#

我认为这可能与下面的突破性变化有关。source
PR编号45176
Route.pathMatch的类型现在更加严格。使用pathMatch的位置可能需要更新为具有显式Route/Routes类型,以便TypeScript不会将类型推断为字符串。
我会给予这个下面一个尝试,看看它是否解决您的问题:

export const routes: Routes = [
  {
    path: 'homepage',
    loadChildren: () =>
      import('src/app/homepage/homepage-component/homepage.module').then(m => m.HomepageModule),
    canActivate: [AuthGuard]
  },
  {
    path: 'sales',
    loadChildren: () =>
      import('src/app/reports/sales-component/sales.module').then(m => m.HomepageModule),
    canActivate: [AuthGuard]
  },
  {
    path: '',
    redirectTo: '/homepage',
    pathMatch: 'full',
  }
gkn4icbw

gkn4icbw2#

请检查src/app/homepage/homepage-component/homepage.module的路径或在此处发布代码。
我很确定你那里有无效的路线。

相关问题