angular / router

The Angular 1 Component Router
MIT License
665 stars 135 forks source link

multi-level routing? #331

Open dlgski opened 9 years ago

dlgski commented 9 years ago

I have multiple applications that I am trying to put together into 1 site. Each application is a typical SPA with it's own routes to navigate to.

I would like to create a base HTML index page that contains the layout of the site. So it would contain the directives for common elements like navbar, side menu, footer and a main view. I want all my individual apps to use this 1 index.html page.

I am looking for a way to have routes that determine the application, followed by a 2nd tier of routes that determine the routing within the SPA.

For example: http://mysite.com/app1/dashboard

The first route check will find app1, bootstrap it to the page and then "dashboard" is an inner route w/in the app1 SPA.

then: http://mysite.com/app2/chartData

This will bootstrap the app2 module to the page (same index.html as above) and app2 will have it's own routes to "chartData"

I do not want all the scripts needed for app1 to load when I'm viewing app2, these are separate apps, just part of the same core site.

Is there... will there be... a way to do this?

alfonso-presa commented 9 years ago

This is something that I've been trying to achieve for a while and...

Short answer.... not right now.

Long answer: you can get close to what you want both with the new router and ui-router (I think that with the old router it will be harder), though you will need a main application that will include the rest of them (one to rule'em all :-) ).

With the new router you can make components for each application and you can easily implement a mechanism to lazy load the application parts needed. The big issue I see is the loading of the routes them self. I mean, you stated you don't want to load the code from app1 prior to resolving a route related to app1, and also I guess that you don't want the routing information of app1 contained inside the application itself.... Then, how will the router know that "/app1/dashboard" is a valid route of app1? Right now there's no router that I know that can handle this situation. It will require the router to include a childrouter for each component (which the new router has) but also a lazy loading step and a "reconfiguration of the grammar" when jumping from the parent router to the child one when needed.