Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
docs: refactor example apps to use dynamic imports for loadChildren
The string syntax for `loadChildren` has been deprecated and is being
removed, so this commit refactors the examples to the new syntax.
  • Loading branch information
JoostK authored and atscott committed Sep 29, 2021
commit 6320c0028e1267683d18543161b5e48b79b562f6
3 changes: 2 additions & 1 deletion modules/playground/src/routing/app/inbox-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export class DraftsCmp {

export const ROUTER_CONFIG = [
{path: '', pathMatch: 'full', redirectTo: 'inbox'}, {path: 'inbox', component: InboxCmp},
{path: 'drafts', component: DraftsCmp}, {path: 'detail', loadChildren: 'app/inbox-detail.js'}
{path: 'drafts', component: DraftsCmp},
{path: 'detail', loadChildren: () => import('./inbox-detail.js').then(mod => mod.default)}
];

@Component({selector: 'inbox-app', templateUrl: './inbox-app.html'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export class HomeView {
declarations: [AppComponent, HomeView],
imports: [
BrowserModule, RouterModule.forRoot([
{path: 'lazy', loadChildren: './lazy.module#LazyModule'},
{path: 'feature2', loadChildren: 'feature2/feature2.module#Feature2Module'},
{path: 'lazy', loadChildren: () => import('./lazy.module').then(mod => mod.LazyModule)}, {
path: 'feature2',
loadChildren: () => import('./feature2/feature2.module').then(mod => mod.Feature2Module)
},
{path: '', component: HomeView}
])
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ export class LazyFeatureComponent {

@NgModule({
imports: [RouterModule.forChild([
{path: '', component: LazyFeatureComponent, pathMatch: 'full'},
{path: 'feature', loadChildren: './feature.module#FeatureModule'},
{path: 'nested-feature', loadChildren: './lazy-feature-nested.module#LazyFeatureNestedModule'}
{path: '', component: LazyFeatureComponent, pathMatch: 'full'}, {
path: 'feature',
loadChildren: () => import('./feature.module').then(mod => mod.FeatureModule)
},
{
path: 'nested-feature',
loadChildren: () =>
import('./lazy-feature-nested.module').then(mod => mod.LazyFeatureNestedModule)
}
])],
declarations: [LazyFeatureComponent]
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export class FeatureComponent {
declarations: [FeatureComponent],
imports: [RouterModule.forChild([
{path: '', component: FeatureComponent},
{path: 'd', loadChildren: './default.module'},
{path: 'e', loadChildren: 'feature/feature.module#FeatureModule'},
{path: 'd', loadChildren: () => import('./default.module').then(mod => mod.default)},
{
path: 'e',
loadChildren: () => import('../feature/feature.module').then(mod => mod.FeatureModule)
},
])]
})
export class Feature2Module {
Expand Down
11 changes: 8 additions & 3 deletions packages/compiler-cli/integrationtest/ngtools_src/lazy.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ export class LazyComponent {

@NgModule({
imports: [[RouterModule.forChild([
{path: '', component: LazyComponent, pathMatch: 'full'},
{path: 'feature', loadChildren: './feature/feature.module#FeatureModule'},
{path: 'lazy-feature', loadChildren: './feature/lazy-feature.module#LazyFeatureModule'}
{path: '', component: LazyComponent, pathMatch: 'full'}, {
path: 'feature',
loadChildren: () => import('./feature/feature.module').then(mod => mod.FeatureModule)
},
{
path: 'lazy-feature',
loadChildren: () => import('./feature/lazy-feature.module').then(mod => mod.LazyFeatureModule)
}
])]],
declarations: [LazyComponent]
})
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export interface Resolve<T> {
* {
* path: 'team/:id',
* component: TeamComponent,
* loadChildren: 'team.js',
* loadChildren: () => import('./team').then(mod => mod.TeamModule),
* canLoad: [CanLoadTeamSection]
* }
* ])
Expand All @@ -449,7 +449,7 @@ export interface Resolve<T> {
* {
* path: 'team/:id',
* component: TeamComponent,
* loadChildren: 'team.js',
* loadChildren: () => import('./team').then(mod => mod.TeamModule),
* canLoad: ['canLoadTeamSection']
* }
* ])
Expand Down