0

I'm working in a larger project where we need to store modules outside an application. Anyone know if it's possible to lazy load a module that's stored outside the src folder?

Example:

./
 - src/
   - app/
     - app.router.ts
       ...
 - +lazy/
   - lazy.module.ts
   - lazy.component.ts
   - lazy.router.ts

In app.router.ts:

{
  path: '',
  loadChildren: '../+lazy/lazy.module#LazyModule'
}

1 Answer 1

0

I found a solution, keep in mind that the lazy loaded module need to have a default export.

export default class LazyModule { }

Router:

{
    path: '',
    loadChildren: () =>
        System.import('../+lazy/lazy.module').then((m: any) => {
            return m.default;
        })
}
Sign up to request clarification or add additional context in comments.

1 Comment

What is System Here, I am getting error saying System is not defined. Do you mean System is SystemJS, If it is SystemJS how do I import it in my route. Is there a way I can make module path as dynamic. I will be getting that dynamic module path from an API.

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.