我有这种情况。
我有两个 Angular 模块:AuthModule
和DashModule
. 这些模块中的每一个都有自己的.routing.ts
文件。
然后,将每个模块导入到AppModule
应用程序级别。
在代码中,这里:
auth.module.ts
位于src/app/auth/auth.module.ts
auth.module.ts
import { NgModule } from '@angular/core';
... // all necessary imports
import { AuthRoutingModule } from './auth-module.routing';
@NgModule({
imports: [
CommonModule,
AuthRoutingModule
],
declarations: [
// all declarations
],
providers: []
})
export class AuthModule { }
src/app/auth/auth-module.routing.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
// all necessary imports
const routes: Routes = [
{ path: 'not-verified', component: NotVerifiedComponent },
{ path: 'login', component: LoginRegisterComponent },
{ path: 'register', component: LoginRegisterComponent },
{ path: 'verify-email/:token', component: VerifyEmailComponent },
{ path: 'reset-password/:token', component: ResetPasswordComponenet },
{ path: 'forgot', component: ForgotComponent },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: []
})
export class AuthRoutingModule { }
DashModule
也遵循与AuthModule
我的src/app/app.routing.ts
样子是这样的:
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { NotfoundComponent } from './pages/notfound/notfound.component';
const appRoutes: Routes = [
// this is more like a catchall route. if all routes fail
{path: '**', component: NotfoundComponent },
];
export const AppRouting: ModuleWithProviders = RouterModule.forRoot(appRoutes);
我的src/app/app.module.ts
样子是这样的:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AppRouting } from './app.routing';
import { AuthModule } from './auth/auth.module';
import { DashModule } from './dash/dash.module';
// Providers
// some providers
@NgModule({
declarations: [
AppComponent,
],
imports: [
...
AuthModule,
DashModule,
AppRouting
],
exports: [ ],
providers: [
// providers here
],
bootstrap: [AppComponent]
})
export class AppModule { }
现在,我可以同时进行加载DashModule
和AuthModule
延迟加载吗?如何?