较低级别的延迟加载结构是否正确?

时间:2017-03-30 20:53:29

标签: angular

我已经设置了一个角度2结构,我真的不知道我是否正在使用延迟加载。我希望我的模块只在需要时加载。也就是说,当它通过url访问时。

主模块和主模块内部还有另一个名为admin的模块。我在管理模块中执行延迟加载。但我停下来认为管理模块在用户身份验证时完全加载。在哪种情况下,里面的内容是懒散的?

以下是我的分析代码:

我的AppModule

...
import {AdminModule}                  from './admin/admin.module';
import { AppComponent }               from './app.component';
import { LoginComponent }             from './login/login.component';
import { RegisterComponent }          from './login/register.component';

@NgModule({
  imports:      [ AdminModule ],
  declarations: [ LoginComponent, RegisterComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

我的app.routes

...
const appRoutes: Routes = [
    { path: 'register', component: RegisterComponent },
    { path: 'login', component: LoginComponent },
    { path: '', component: LoginComponent }
];
...

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);

我的adminModule

import { adminRouting }       from './admin.routing';
import { AdminComponent }     from './admin.component';
import { HomeComponent }      from './home/home.component';

@NgModule({
  imports: [ adminRouting ],
  declarations: [ AdminComponent, HomeComponent ],
  providers:[ ]
})
export class AdminModule {}

我的adminRouting

const imagesRoutes: Routes = [
  {
    path: 'images',
    loadChildren: 'app/admin/images/images.module#ImagesModule',
    canLoad: [AuthGuard]
  }
];

const updatesRoutes: Routes = [
  {
    path: 'updates',
    loadChildren: 'app/admin/updates/updates.module#UpdatesModule',
    canLoad: [AuthGuard]
  }
];

const adminRoutes: Routes = [{

    path: 'admin',
    component: AdminComponent,
    canActivate: [AuthGuard],
    children: [

        { path: '', component: HomeComponent },
        ...imagesRoutes,
        ...updatesRoutes

    ]

  }];



export const adminRouting: ModuleWithProviders = RouterModule.forChild(adminRoutes);

0 个答案:

没有答案