Do you know a way in ui-router to get the list of child states of a given state?
I'm implementing a complex SPA with maybe 4 level deep navigation using ui-router.
I would like to implement a navigation tab interface for the second level generated automatically from the router table.
For that, I need to get the list of direct children of a given state (maybe is an abstract state). The only way that I've found to get the states is to do a $state.get()
and obtain the full list of states, but that means that I'll have to parse child states on my own, and I think that's code already written in ui-router.
I let this question here in case there's anyone with experience in the source code or know of a plugin or module that can help me on this. Meanwhile I will do a research on my own and post results if I find something.
I did this which is easier and faster:
In the end, had to implement the functionality myself.
In the controller of the abstract route that has the tab interface, filtered the states using a regular expression taking advantage of the default naming convention for routes:
My route definitions have a
data
property that contains the title and other metadata needed to render the tabs.My template looks something like this (using bootstrap):
If you use stateHelper, it enables you to register states like this (from the stateHelper readme):
In your navigation controller you can then use the
children
attribute on the "root" state. For instance, I'm using this to display all children of the current state:Hope this helps.