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

前端 未结 6 978
陌清茗
陌清茗 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条回答
  •  -上瘾入骨i
    2020-11-30 01:12

    Both @N13 and I could not make @Josh's solution work. But this did work for me:

        module.config(['$routeProvider', function($routeProvider){
            $routeProvider.accessWhen = function(path, route){
                route.resolve || (route.resolve = {});
                route.resolve.language = "something"
                return $routeProvider.when(path, route);
            };
        }]);
    

    use with:

    $routeProvider
            .accessWhen('/login', {
               ...
            });
    

提交回复
热议问题