AngularJS : How to use one resolve for all the routes of my application

前端 未结 6 982
陌清茗
陌清茗 2020-11-30 00:53

I would like to resolve the promise that loads the current user for all the pages of my application. Currently I repeat the resolve in every $routeProvider.when()

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 01:14

    I found that this case much better:

    angular.extend({}, $routeProvider, {
      when: function(path, route) {
        route.resolve || (route.resolve = {});
        route.resolve = angular.merge({}, route.resolve, {
          chef: 'OrganizationCheckerProvider'
        });
        return $routeProvider.when(path, route);
      }
    });
    

提交回复
热议问题