Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature Request:[router] Support for configuring Routes lazily & dynamically using a service #8590
Comments
|
Routes are per component. I don't see how this should work. |
|
You can load components lazily. Have you tried loading a component lazily that has a routeconfig? |
|
@zoechi RouteMetaData was recently updated with component parameter now supporting string type. This was for lazy loading the components as you no longer require to add import statement for components. The service could return an array of RouteMetaData with component name as string and the router could lazy load those components. |
|
@b-strauss Even if I lazy load components, I will have to define all possible routes from that component in my code statically. I want the possible routes to be configured dynamically and loaded lazily based on the user authorizations . |
|
The RouteConfig accepts a simple array object. Can't you load a module that has a function that gets a route config array and returns a component? I have not yet tried this myself. export function getMyComponent(config: Array): Type {
@Component({
selector: 'my-component'
})
@RouteConfig(config)
class MyComponent{
constructor() {
}
}
return MyComponent;
} |
|
@b-strauss I have seen similar examples of creating components and it looks OK for sample apps. I think we need a cleaner approach to handle this. |
|
@ajayambre But how is that different to a "normal" component that isn't nested inside a function? If your component has that much code, it should be broken up into smaller parts anyway. I don't see whats "not clean" about this solution (if it really works): |
|
@b-strauss Thanks for your inputs on this. I will give it a try to see if that works. |
|
@ajayambre Well, unfortunately EcmaScript doesn't have configurable modules imports (few languages have). So yes. :) But I think this is a shortcoming of the language not angular. Btw.: The only component you need to import like this is the one that sits at the top of your routes. Subroutes of that component can be imported normally again. |
|
@b-strauss Have a look at this http://plnkr.co/edit/IwdcGvAokzFX8CxJEFpc?p=preview Thanks in advance :) |
|
@mhevery I am on RC1 and wanted this feature in the new router. Is this already in plan for the new router? Why was this labelled comp:router-deprecated and not comp: router? Thanks. |
|
Yes, this will be part of the new router. |
|
Even, I have the similar use case. Building Menu from the data provided by service ,which is achievable. But assinging this data from service to |
|
@mhevery Any news when this is planned? I need this feature in order to upgrade my projects to RC :) |
|
This would be awesome, is the solution that are comming also covering my problem @mhegazy? http://stackoverflow.com/questions/37361604/angular-2-pretty-routing-api-based |
|
We are no longer maintaining the deprecated router to focus our efforts on making the new router solid. This functionality is implemented in the new router. So I'm closing this issue. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Use Case
Expected/desired behavior
Support for configuring Routes lazily and dynamically using a service after the user logs in.