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

前端 未结 6 992
陌清茗
陌清茗 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:15

    For the people stuck with old code bases.

    const _when = $routeProvider.when;
    $routeProvider.when = (path, route) => _when.call($routeProvider, path, {
      ...route,
      resolve: {
        ...route.resolve,
        'currentUser': [ 'UserService', UserService => UserService.getCurrentUser() ]
      }
    });
    

提交回复
热议问题