Архитектура проекта: -
app Module > Public Module > Home Module > Article Module etc:--
> Member Module > Blog Module > Album Module etc:--
> Admin Module > dashboard Module > Product Module etc:-
Небольшое изменение: -
app Module> LayoutModule >
> Public Module > Home Module > Article Module etc:
> Member Module > Blog Module > Album Module etc:--
> Admin Module > dashboard Module > Product Module etc:-
Каждый модуль имеет - .ts,.html,.spec,.scss,.routing, .module files in Project architecture
app.routing.ts
import { NgModule, ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
export const routes: Routes = [
{
path: '',
redirectTo: '',
pathMatch: 'full'
},
{
path: '**',
redirectTo: 'error',
}
];
export const Routing: ModuleWithProviders = RouterModule.forRoot(routes, { useHash: true });
app.component.html
<router-outlet></router-outlet>
app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
MainLayoutModule ,
Routing,
GrowlModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
MainLayout.routing.ts
export const routes: Routes = [
{
path: '',
component: MainLayoutComponent,
children: [
{ path: '', redirectTo: 'public', pathMatch: 'full' },
{ path: 'public', loadChildren: './public/public.module#PublicModule' },
{ path: 'home', loadChildren: './home/home.module#HomeModule' },
{ path: 'article', loadChildren: './article/article.module#articleModule' },
{ path: 'memeber', loadChildren: './memeber/memeber.module#memeberModule' },
'
'
'
'
]
}
];
export const PrgRouting = RouterModule.forChild(routes);
MainLayout.module.ts
@NgModule({
imports: [
CommonModule,
PrgRouting,
],
declarations: [
MainLayoutComponent,
],
providers: []
})
export class MainLayoutModule { }
Любые другие модули: -
export const routes: Routes = [
{
path: '',
component: ArticleComponent,
children: [
{ path: 'pages', component: PagesComponent },
{ path: 'mucomponent', component: MyComponent }
]
}
];
export const routing = RouterModule.forChild(routes);
Любой Module.ts
@NgModule({
imports: [
CommonModule,
routing,
SharedModule
],
declarations: [ArticleComponent]
})
export class ArticleModule { }
article.component.html
<router-outlet></router-outlet>
См.: - https://angular -2-training-book.rangle.io / handout / modules / lazy-loading-module.html