How to redirect in a ui-router resolver?

前端 未结 7 731
我寻月下人不归
我寻月下人不归 2021-02-03 17:58

I am trying to redirect inside a ui-router resolve and wanted to know if there is a way to reroute in a router resolver. Currently this does not work as one would think.

7条回答
  •  庸人自扰
    2021-02-03 18:33

    This is what I actually do, and I can't find a better solution

    resolver($q, $timeout, myService) {
        if(!areParameterValuesValid() || !isEverythingLogicallyOk()){
            var deferred = $q.defer();
            $timeout(function() {
                $state.go('somewhere');
                deferred.reject();
            });
            return deferred.promise;
        } else {
            return myService.loadSomething(passingSomeParams);
        }        
    }
    

提交回复
热议问题