Skip to content

Commit e1af6e3

Browse files
brandonrobertsjasonaden
authored andcommitted
docs: use dynamic import syntax in examples using lazy loading (angular#30563)
PR Close angular#30563
1 parent 9e946c9 commit e1af6e3

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

aio/content/examples/lazy-loading-ngmodules/src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { Routes, RouterModule } from '@angular/router';
88
const routes: Routes = [
99
{
1010
path: 'customers',
11-
loadChildren: './customers/customers.module#CustomersModule'
11+
loadChildren: () => import('./customers/customers.module').then(mod => mod.CustomersModule)
1212
},
1313
{
1414
path: 'orders',
15-
loadChildren: './orders/orders.module#OrdersModule'
15+
loadChildren: () => import('./orders/orders.module').then(mod => mod.OrdersModule)
1616
},
1717
{
1818
path: '',

aio/content/examples/ngmodules/src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Routes, RouterModule } from '@angular/router';
33

44
export const routes: Routes = [
55
{ path: '', redirectTo: 'contact', pathMatch: 'full'},
6-
{ path: 'items', loadChildren: './items/items.module#ItemsModule' },
7-
{ path: 'customers', loadChildren: './customers/customers.module#CustomersModule' }
6+
{ path: 'items', loadChildren: () => import('./items/items.module').then(mod => mod.ItemsModule) },
7+
{ path: 'customers', loadChildren: () => import('./customers/customers.module').then(mod => mod.CustomersModule) }
88
];
99

1010
@NgModule({

aio/content/examples/router/src/app/app-routing.module.5.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const appRoutes: Routes = [
2020
// #docregion admin, admin-1
2121
{
2222
path: 'admin',
23-
loadChildren: './admin/admin.module#AdminModule',
23+
loadChildren: () => import('./admin/admin.module').then(mod => mod.AdminModule),
2424
// #enddocregion admin-1
2525
canLoad: [AuthGuard]
2626
// #docregion admin-1

aio/content/examples/router/src/app/app-routing.module.6.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ const appRoutes: Routes = [
2121
},
2222
{
2323
path: 'admin',
24-
loadChildren: './admin/admin.module#AdminModule',
24+
loadChildren: () => import('./admin/admin.module').then(mod => mod.AdminModule),
2525
canLoad: [AuthGuard]
2626
},
2727
{
2828
path: 'crisis-center',
29-
loadChildren: './crisis-center/crisis-center.module#CrisisCenterModule'
29+
loadChildren: () => import('./crisis-center/crisis-center.module').then(mod => mod.CrisisCenterModule)
3030
},
3131
{ path: '', redirectTo: '/heroes', pathMatch: 'full' },
3232
{ path: '**', component: PageNotFoundComponent }

aio/content/examples/router/src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ const appRoutes: Routes = [
1717
},
1818
{
1919
path: 'admin',
20-
loadChildren: './admin/admin.module#AdminModule',
20+
loadChildren: () => import('./admin/admin.module').then(mod => mod.AdminModule),
2121
canLoad: [AuthGuard]
2222
},
2323
// #docregion preload-v2
2424
{
2525
path: 'crisis-center',
26-
loadChildren: './crisis-center/crisis-center.module#CrisisCenterModule',
26+
loadChildren: () => import('./crisis-center/crisis-center.module').then(mod => mod.CrisisCenterModule),
2727
data: { preload: true }
2828
},
2929
// #enddocregion preload-v2

aio/content/examples/testing/src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AboutComponent } from './about/about.component';
88
RouterModule.forRoot([
99
{ path: '', redirectTo: 'dashboard', pathMatch: 'full'},
1010
{ path: 'about', component: AboutComponent },
11-
{ path: 'heroes', loadChildren: './hero/hero.module#HeroModule'}
11+
{ path: 'heroes', loadChildren: () => import('./hero/hero.module').then(mod => mod.HeroModule)}
1212
])
1313
],
1414
exports: [ RouterModule ] // re-export the module declarations

aio/content/guide/lazy-loading-ngmodules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ In `AppRoutingModule`, update the `routes` array with the following:
143143
</code-example>
144144

145145

146-
The import statements stay the same. The first two paths are the routes to the `CustomersModule` and the `OrdersModule` respectively. Notice that the lazy loading syntax uses `loadChildren` followed by a string that is the relative path to the module, a hash mark or `#`, and the module’s class name.
146+
The import statements stay the same. The first two paths are the routes to the `CustomersModule` and the `OrdersModule` respectively. Notice that the lazy loading syntax uses `loadChildren` followed by a function that uses the browser's built-in `import('...')` syntax for dynamic imports. The import path is the relative path to the module.
147147

148148
### Inside the feature module
149149

aio/content/guide/router.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,10 +3954,10 @@ Users will still visit `/admin` and the `AdminComponent` still serves as the *Ro
39543954

39553955
Open the `AppRoutingModule` and add a new `admin` route to its `appRoutes` array.
39563956

3957-
Give it a `loadChildren` property instead of a `children` property, set to the address of the `AdminModule`.
3958-
The address is the `AdminModule` file location (relative to the app root),
3959-
followed by a `#` separator, followed by the name of the exported module class, `AdminModule`.
3960-
3957+
Give it a `loadChildren` property instead of a `children` property.
3958+
The `loadChildren` property takes a function that returns a promise using the browser's built-in syntax for lazy loading code using dynamic imports `import('...')`.
3959+
The path is the location of the `AdminModule` (relative to the app root).
3960+
After the code is requested and loaded, the `Promise` resolves an object that contains the `NgModule`, in this case the `AdminModule`.
39613961

39623962
<code-example path="router/src/app/app-routing.module.5.ts" region="admin-1" header="app-routing.module.ts (load children)">
39633963

0 commit comments

Comments
 (0)