Skip to content

Commit 55dfe80

Browse files
BeGjalxhub
authored andcommitted
docs: standalone component preloading config (#50193)
The preloading modules documentation were missing information about how to apply preloading strategies to standalone application ( `ng new AppName --standalone` ). Feel free to fix anything not in line with the Angular documentation style guide, as this is my first attempt at contributing :) - Added example for `app.config.ts` providing info on the `withPreloading(<preloading strategy>)` you can add to the `provideRouter()` RouterFeatures. - Specified that preloading modules also applies for standalone components. PR Close #50193
1 parent 69dadd2 commit 55dfe80

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

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

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,15 @@ For more information, see the [`forRoot()` pattern](guide/singleton-services#for
251251
## Preloading
252252

253253
Preloading improves UX by loading parts of your application in the background.
254-
You can preload modules or component data.
254+
You can preload modules, standalone components or component data.
255255

256-
### Preloading modules
256+
### Preloading modules and standalone components
257257

258-
Preloading modules improves UX by loading parts of your application in the background. By doing this, users don't have to wait for the elements to download when they activate a route.
258+
Preloading modules and standalone components improves UX by loading parts of your application in the background. By doing this, users don't have to wait for the elements to download when they activate a route.
259259

260-
To enable preloading of all lazy loaded modules, import the `PreloadAllModules` token from the Angular `router`.
260+
To enable preloading of all lazy loaded modules and standalone components, import the `PreloadAllModules` token from the Angular `router`.
261+
262+
### Module based application
261263

262264
<code-example header="AppRoutingModule (excerpt)">
263265

@@ -278,6 +280,32 @@ RouterModule.forRoot(
278280

279281
</code-example>
280282

283+
### Standalone application
284+
285+
For standalone applications configure preloading strategies by adding `withPreloading` to `provideRouter`s RouterFeatures in `app.config.ts`
286+
287+
<code-example header="`app.config.ts`">
288+
289+
import { ApplicationConfig } from '@angular/core';
290+
import {
291+
PreloadAllModules,
292+
provideRouter
293+
withPreloading,
294+
} from '@angular/router';
295+
296+
import { routes } from './app.routes';
297+
298+
export const appConfig: ApplicationConfig = {
299+
providers: [
300+
provideRouter(
301+
routes,
302+
withPreloading(PreloadAllModules)
303+
),
304+
],
305+
};
306+
307+
</code-example>
308+
281309
### Preloading component data
282310

283311
To preload component data, use a `resolver`.
@@ -401,4 +429,4 @@ You might also be interested in the following:
401429

402430
<!-- end links -->
403431

404-
@reviewed 2022-02-28
432+
@reviewed 2022-05-07

0 commit comments

Comments
 (0)