未捕获(承诺中):错误:运行时编译器未加载 Angular 8

2024-02-23

我正在尝试从 JSON 文件加载路由。路由中还有一个延迟加载的模块。一切都按预期工作,直到代码在 aot 模式下的 ng build --prod 中运行。当我尝试转到延迟加载模块链接时,出现以下错误。代码如下:

应用程序路由模块.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule, Router } from '@angular/router';
import * as AppRoutingJson from '../assets/data/routing.json';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { RouteoneComponent } from './routeone/routeone.component';
import { RoutetwoComponent } from './routetwo/routetwo.component';

const routes: Routes =[];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  entryComponents: [PageNotFoundComponent, RouteoneComponent, RoutetwoComponent],
})
export class AppRoutingModule {
  constructor(private router: Router) {
    this.prepareRoutes(AppRoutingJson);
  }

  prepareRoutes(routesJson: any) {
    let routesArr = [] as Routes;

    routesArr = [
      {
        path: 'routeone',
        component: RouteoneComponent,
      },
      {
        path: 'routetwo',
        component: RoutetwoComponent,
      },
      { path: 'contact', loadChildren: () => import('./contact/contact.module').then(m => m.ContactModule)},
      { path: 'dv', loadChildren: './modules/dv.module#DVModule' },
    ];
   // routesArr=AppRoutingJson;
    routesArr.forEach(route => {
      routes.push(route);
    });

    routes.push(
      {
        path: 'page-not-found',
        component: PageNotFoundComponent,
      },
      {
        path: '**',
        redirectTo: 'page-not-found',
      }
    );
    console.log(routes);
    this.router.resetConfig(routes);
  }
}

错误如下:


这似乎是一个常见问题。看这里:https://github.com/angular/angular-cli/issues/10582 https://github.com/angular/angular-cli/issues/10582和这里:https://github.com/angular/angular/issues/23878 https://github.com/angular/angular/issues/23878

我建议使用字符串语法contact路线,所以:

loadChildren: './contact/contact.module#ContactModule'

这似乎可以为其他人解决 GitHub 问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未捕获(承诺中):错误:运行时编译器未加载 Angular 8 的相关文章

随机推荐