Javascript 如何在js中限制登录用户在登录页面或注册页面上移动?

Javascript 如何在js中限制登录用户在登录页面或注册页面上移动?,javascript,angularjs,Javascript,Angularjs,我有以下代码: .run(function($rootScope, $location, Auth) { //Redirect to login if route requires auth and you're not logged in $rootScope.$on('$routeChangeStart', function(event, next) { Auth.isLoggedInAsync(function(loggedIn) { if

我有以下代码:

.run(function($rootScope, $location, Auth) {

    //Redirect to login if route requires auth and you're not logged in
    $rootScope.$on('$routeChangeStart', function(event, next) {

       Auth.isLoggedInAsync(function(loggedIn) {
        if (!loggedIn) {//when user is not logged in
          if ($location.path() == "/participant/signup" || $location.path() == "/researcher/signup" || $location.path() == "/participant/login" || $location.path() == "/researcher/login" || $location.path() == "/admin/login");

          else{
            $location.path('/homePage');
          }
        }
        else if(loggedIn){ //when user loged in
          if ($location.path() == "/participant/signup" || $location.path() == "/researcher/signup" || $location.path() == "/participant/login" || $location.path() == "/researcher/login" || $location.path() == "/admin/login"){
            event.preventDefault();
            //event.stopPropagation();
          }
        }
      });
    });
  })
我想限制登录用户在登录或注册页面上移动。以上代码不起作用,请告诉我哪里做错了。如果你有一个很好的处理方法,请建议

Define an interceptor to handle user status

angular.module('App').factory('authInterceptor', ['$location', 'Auth', function ($location, Auth) {

        var authInterceptorService = {};
        if (!Auth.isLoggedIn)
            $location.url('/login');

        return authInterceptorService;
    }]);
在App.js中

angular.module('App').config(function ($httpProvider) {
    $httpProvider.interceptors.push('authInterceptorService');
});