19

Is there any way to get the list of states configured for the application through Angularjs UI Router? i.e After configuring all the states (aka routes in angular), how to get the array of these states or state objects.

In other words, what is the equivalent of Angular's built in router's "$route.routes" in Angular UI Router?

Tried to find in UI Router's api documentation, but can't find it.

0

1 Answer 1

38

Use $state.get().

Following in your controller

app.controller('MainCtrl', function ($state) {
  console.log(angular.toJson($state.get()));
});

Would spit out something like

[{  
  "name":"",
  "url":"^",
  "views":null,
  "abstract":true
 },{  
  "name":"main",
  "url":"/main",
  "controller":"MainCtrl",
  "templateUrl":"main.html"
}]
Sign up to request clarification or add additional context in comments.

2 Comments

Seems like it's been covered here too stackoverflow.com/a/21593863/1061668
It doesn't look like this works, after injecting $state I just get $state.get() is not a function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.