Get a list of routes from $ routeProvider to angular

I have an application where routes are defined as follows:

angular.module('myApp').config(['$routeProvider', function ($routeProvider) {
  'use strict';

  $routeProvider

    .when('/user-management', {
      title: 'Manage: Users',
      permissions: ['ADMINISTRATOR'],
      templateUrl: 'views/user-management.html',
      controller: 'UserCtrl'
    })

    .when('/group-management', {
      title: 'Manage: Groups',
      templateUrl: 'views/group-management.html',
      controller: 'GroupManagementCtrl',
      permissions: ['OPERATOR', 'ADMINISTRATOR']
    })
...

In the controller, I would like to get this list of routes, as well as access permissions for each of the routes. This would have to hide the navigation elements for pages for which you do not have rights.

Is there a good way to get a list of routes and their associated permissions?

+4
source share
1 answer

You can access all routes (and additional type properties permissions) from $route.routes. See https://docs.angularjs.org/api/ngRoute/service/$route .

Excerpts:

routes: with all route configuration Objects as its properties.
+6
source

All Articles