How to redirect in a ui-router resolver?

前端 未结 7 726
我寻月下人不归
我寻月下人不归 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:27

    I think a much cleaner answer is to return an already rejected promise like so:

    resolver(auth, $state, $q){
       if(!auth.isLoggedIn()){
           $state.go('noLoggedInPath');
           
           // Return rejected promise
           return $q.reject();
       }
       return true;
    }

提交回复
热议问题