是否可以在没有路由文件的情况下使用角度延迟加载

时间:2019-10-30 17:37:51

标签: angular lazy-loading

我正在为模块使用角延迟加载。

例如,我按照AG8的建议加载了这样的模块

const routes: Routes = [
  {path: 'home', component: HomeComponent, data: {title: 'Home', animation: 'Home'}},
  {path: 'services', loadChildren: () => import('./modules/services.module').then(module => module.ServicesModule), data: {title: 'Services', animation: 'Services'}},
  // {path: '', redirectTo: 'home', pathMatch: 'full'},
  {path: 'login', loadChildren: () => import('./modules/login.module').then(module => module.LoginModule), data: {title: 'Login', animation: 'Login'}},
  {path: 'dashboard', loadChildren: () => import('./modules/dashboard.module').then(module => module.DashboardModule ), data: {title: 'Dashboard', animation: 'Dashboard'}, canActivate: [AppAuthGuard]},
  {path: 'user/:userID/event/:eventID', loadChildren: () => import('./modules/event.module').then(module => module.EventModule ), data: {title: 'Event Details', animation: 'Event'}},
  {path: 'user/:userID', loadChildren: () => import('./modules/user.module').then(module => module.UserModule), data: {title: 'Profile', animation: 'User'}},
  {path: '**', redirectTo: 'home', pathMatch: 'full' },
];

对于每个模块,我都有其对应的文件,例如:

@NgModule({
  imports: [
    CommonModule,
    SomeRoutingModule
  ],
  declarations: [SomeComponent]
})
export class SomeModule { }

但是对于所有这些模块,我必须创建其相应的路由器文件,例如:

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

有没有一种方法可以仅从父模块中引导路线来加载懒惰模块的已声明组件,而无需创建路由器文件?

类似:

loadChildren: () => import('./modules/services.module').then(module => module.ServicesModule.SomeComponent)

0 个答案:

没有答案