1

Is it possible to lazy load standalone component for multiple path's? Is this a proper way to do it?

{ path: 'path1', loadComponent: () => import('./someComponent.component').then(c => c.someComponent)},
{ path: 'path2', loadComponent: () => import('./someComponent.component').then(c => c.someComponent)},

In main.ts file I also set preoload strategy to preload all modules:

provideRouter(APP_ROUTES, withPreloading(PreloadAllModules))

I checked newtwork in DevTools and it looks like component is loaded only once. However I am not sure if this is the correct way of implementing it.

1 Answer 1

1

The way you are lazy leading is absolutely fine. because regardless of how many times you are lazy loading a component or a module, it will load only the first time and the next time Angular loads the same route or another route with same component or module, Angular will use the already loaded component or module.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.