As discussed in the comments, angular
has a really powerful feature/library for handling these scenarios - ui-router
(with its powerful wiki).
The ui-router
is an answer to need to develop functional pieces - states, rather then think in view/url (cite from a home page):
AngularUI Router is a routing framework for AngularJS, which allows you to organize the parts of your interface into a state machine. Unlike the $route service in the Angular ngRoute module, which is organized around URL routes, UI-Router
is organized around states, which may optionally have routes, as well as other behavior, attached.
There are some very interesting blog posts:
...The most interesting thing about AngularJS's new router, isn't the router itself, but the state manager that comes with it. Instead of targeting a controller/view to render for a given url, you target a state. States are managed in a heirarchy providing inheritance of parent states and complex composition of page components, all the while remaining declarative in nature...
...ui-router
fully embraces the state-machine nature of a routing system. It allows you to define states, and transition your application to those states. The real win is that it allows you to decouple nested states, and do some very complicated layouts in an elegant way.
Exactly the point we need - decouple child states... dynamically change the controller in fact ... could be by url change or just a state change (one sibling child instead of other without url change)
You need to think about your routing a bit differently, but once you get your head around the state-based approach, I think you will like it...
Finally, there are few links, which I would mark as the saint grail of ui-router
Sample application. In action we can see, how the ui-router state machine does work. We can load list as a parent state, then we can select row items, which do represent their own child state... while parent is not reloading (here I tried to explain it in more details)
state.js
- the essential piece of code of the sample application. This is one of the best documented code snippets I've seen... Spent some time to go through and this will give you the 80% percent of answers: How ui-Router
is working
From my experience, this is really suitable for small apps as well as for large scale systems... love it...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…