简体   繁体   中英

get list of routes from $routeProvider in angular

I have an app where routes are defined like so:

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 a controller I would like to be able to get this route list and also be able to access the permissions for each of the routes. This would be to hide nav elements for pages you don't have permission to.

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

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

Excerpt:

routes: with all route configuration Objects as its properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM