2

Problem I have an Content Management System Angular application where all components are present in main component. Routes are created dynamically for this components (at runtime).

E.g. a page is created with name A, then dynamically a route can be created with a path :sname/route/to/pageA which displays the component (sname is the domain name).

This process works fine but all the components need to be in the main bundle for this to work.

As the app is growing bigger lazy loading becomes more and more necessary. Is there any possible way to create this kind of lazy loading components dynamically? I imagine that all of the components that can be dynamically added to routes need to have their own lazy loaded module. What I am now missing is how these modules are integrated with dynamic routes (which are only known at runtime) to the lazy loading process.

I am not necessarily looking for exact source code but also any pointers to potential approaches/similar projects would be incredibly helpful.

We have tried traditional route based lazy loading but it is not working, since the routes are dynamic. Also the libraries for lazy loading of components are not working, as we are using dynamic routing and can't predict which components will be used and those libraries load a component based on the action eg. click, hover etc.

app-routing.module.ts

2
  • what do you mean by dynamic routes? Can you post the code? Because your app routing looks standard routes, and should work as expected with lazy loading. Which errors do you get? Commented Mar 2, 2023 at 9:23
  • i have the same problem right now :D Commented Sep 8, 2023 at 2:58

0

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.