Skip to content

docs(angular): use lazy loading - reworked exemples for standalone co… #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
71 changes: 68 additions & 3 deletions angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -905,25 +905,90 @@ When possible, try to lazy load the modules in your Angular application. Lazy lo
```ts
const routes: Routes = [
{
path: '',
pathMatch: 'full',
path: 'home',
component: HomeComponent,
},
];
```

### Exemple using standalone components

**After**

```ts
// app-routing.module.ts
const routes: Routes = [
{
path: 'home',
loadChildren: () => import('./next-flight/home.component').then(m => m.HomeComponent)
},
];
```

### Exemple using another routing config

**After**

```ts
// app-routing.module.ts
const routes: Routes = [
{
path: 'home',
loadChildren: () => import('./next-flight/home.routes').then(m => m.routes)
},
];
```

```ts
// home.routes.ts
const routes: Routes = [
{
path: '',
pathMatch: 'full',
component: HomeComponent,
},
];
```

### Exemple using modules

**After**

```ts
// app-routing.module.ts
const routes: Routes = [
{
path: 'home',
loadChildren: () => import('./features/home/home.module').then(m => m.HomeModule),
},
];
```

```ts
// home-routing.module.ts
const routes: Routes = [
{
path: 'home',
component: HomeComponent
}
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class HomeRoutingModule {}
```

```ts
// home.module.ts
@NgModule({
imports: [
HomeRoutingModule,
],
})
export class HomeModule {}
```

## Use index.ts

Instead of remembering multiple source file names, there are some tiny import statements that will fulfill the purpose.
Expand Down