Не перехвачено (в обещании): ChunkLoadError: Ошибка загрузки чанка xxx-xxx-module. Angular 9 - PullRequest
0 голосов
/ 25 мая 2020

Angular 9: Ленивая загрузка / маршрутизатор не работает должным образом

Сообщения об ошибках консоли

ERROR Error: Uncaught (in promise): ChunkLoadError: Loading chunk frame-frame-module failed.


Path URL: /author

http://local.xxxxx.com/node/190/author

Code

app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { AppComponent } from './app/app.component';
import { HomeComponent } from './home/home.component';
import { BlankComponent } from './blank/blank.component';

const childRoutes = [
  {
    path: 'author/preview',
    data: {
      routeLabel: 'preview'
    },
    loadChildren: () => import('./frame/frame.module').then(m => m.FrameModule)
  },
  {
    path: 'author',
    canActivate: [DraftContentGuard, ContentEditorAccessGuard],
    data: {
      routeLabel: 'edit'
    },
    loadChildren: () => import('./frame/frame.module').then(m => m.FrameModule)
  },
];

const routes: Routes = [
  {
    path: ':locale/:type/:contentId',
    component: AppComponent,
    canActivate: [EnabledWebSegmentAccessGuard],
    children: childRoutes
  },
  {path: 'author', component: HomeComponent},
  {path: '', redirectTo: '/author', pathMatch: 'full'},
  {path: '**', component: BlankComponent}
];

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

frame.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { FrameRoutingModule } from './frame-routing.module';
import { FrameComponent } from './frame.component';

@NgModule({
    imports: [
        CommonModule,
        FrameRoutingModule
    ],
    declarations: [FrameComponent]
})

export class FrameModule { }

frame-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { FrameComponent } from './frame.component';


const routes: Routes = [
    {
        path: '',
        component: FrameComponent,
    }
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule]
})

export class FrameRoutingModule { }

Структура проекта

Project folders


What do I think?

The majority of the documentation, articles, tutorials, are using a different localhost server, so I am not sure if my server configuration should change to work properly with the lazy loading.

Файла нет на моем сервере

1 Ответ

0 голосов
/ 26 июля 2020

У меня такая же проблема. Затем я изменил следующее

Я не знаю, правильная ли это процедура, но она сработала для меня

{ path: '<$Path>',loadChildren:() => import('./<$module folder name>/<$YOUR Module name>.module').then(m => m.<$Modulename>)}  

вместо этого я изменил на

import {<$Modulename>} from '/<$Modulepath>';
{ path: '<$Path>', loadChildren:() => {return <$Modulename>;}  }
...