Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request:[router] Support for configuring Routes lazily & dynamically using a service #8590

Closed
ajayambre opened this issue May 11, 2016 · 17 comments

Comments

@ajayambre
Copy link
Contributor

@ajayambre ajayambre commented May 11, 2016

Use Case

An application has multiple modules and each module has multiple navigation menu items in it.
Both modules and navigation menu items are authorization driven and fetched using a module and menu service from the server after the user logs in.

Expected/desired behavior

Support for configuring Routes lazily and dynamically using a service after the user logs in.

@zoechi
Copy link
Contributor

@zoechi zoechi commented May 11, 2016

Routes are per component. I don't see how this should work.

@b-strauss
Copy link

@b-strauss b-strauss commented May 11, 2016

You can load components lazily. Have you tried loading a component lazily that has a routeconfig?

@ajayambre
Copy link
Contributor Author

@ajayambre ajayambre commented May 11, 2016

@zoechi RouteMetaData was recently updated with component parameter now supporting string type.
https://github.com/angular/angular/blob/master/modules/%40angular/router/src/metadata/metadata.ts#L25

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.

@ajayambre
Copy link
Contributor Author

@ajayambre ajayambre commented May 11, 2016

@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 .

@b-strauss
Copy link

@b-strauss b-strauss commented May 11, 2016

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;
}
@ajayambre
Copy link
Contributor Author

@ajayambre ajayambre commented May 11, 2016

@b-strauss I have seen similar examples of creating components and it looks OK for sample apps.
But in a large scale enterprise application, the component will have complex templates and lots of other functions and logic associated to it.

I think we need a cleaner approach to handle this.

@b-strauss
Copy link

@b-strauss b-strauss commented May 11, 2016

@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):

@ajayambre
Copy link
Contributor Author

@ajayambre ajayambre commented May 11, 2016

@b-strauss Thanks for your inputs on this. I will give it a try to see if that works.
What if I have multiple such components? Do I need to have multiple getMyComponents?
Would prefer a public api though which handles this. :)

@b-strauss
Copy link

@b-strauss b-strauss commented May 11, 2016

@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.

@ajayambre
Copy link
Contributor Author

@ajayambre ajayambre commented May 11, 2016

@b-strauss Have a look at this http://plnkr.co/edit/IwdcGvAokzFX8CxJEFpc?p=preview
You will get an idea of what I am trying to achieve.
The modules and screens have to be fetched based on user authorizations and links created dynamically. Each screen could be a different component with different view template and functions.

Thanks in advance :)

@ajayambre
Copy link
Contributor Author

@ajayambre ajayambre commented May 13, 2016

@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.

@mhevery
Copy link
Member

@mhevery mhevery commented May 13, 2016

Yes, this will be part of the new router.

@sirajc
Copy link

@sirajc sirajc commented May 17, 2016

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 @Routes is not. It would be good to have a public API for this on New Router

@dominikstrasser
Copy link

@dominikstrasser dominikstrasser commented May 30, 2016

@mhevery Any news when this is planned? I need this feature in order to upgrade my projects to RC :)
ps: The label of this issue should be changed to the new router and not the router-deprecated.

@LennardWesterveld
Copy link

@LennardWesterveld LennardWesterveld commented Jun 6, 2016

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

@vsavkin
Copy link
Contributor

@vsavkin vsavkin commented Jul 6, 2016

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.

@vsavkin vsavkin closed this Jul 6, 2016
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Sep 9, 2019

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.