Javascript 登录后angularjs重定向

Javascript 登录后angularjs重定向,javascript,angularjs,Javascript,Angularjs,我可以知道如何在用户登录后将其重定向到原来的位置吗?假设我有一篇文章www.example.com/post/435,它要求用户登录才能“喜欢/评论”该文章,那么在用户登录后,我如何将用户重定向回该文章?我试过这个 $http.post('/sessionHandler/login',$scope.form). success(function(data){ history.back(); // bring user back to previous path

我可以知道如何在用户登录后将其重定向到原来的位置吗?假设我有一篇文章
www.example.com/post/435
,它要求用户登录才能“喜欢/评论”该文章,那么在用户登录后,我如何将用户重定向回该文章?我试过这个

 $http.post('/sessionHandler/login',$scope.form).
      success(function(data){
        history.back(); // bring user back to previous path
      }).error(function(err){
        $scope.errorMessage = err;
      });
但是,这并不是真正有效的,如果用户以前的路径是其他站点或浏览器的新选项卡,它会将用户重定向回他们所在的位置

我还通过使用
$locationChangeStart
找到了一些示例,但我很难理解它是如何工作的,这就是我到目前为止对
$locationChangeStart

$http.post('/sessionHandler/login',$scope.form).
      success(function(data){
   $rootScope.$on("$locationChangeStart", function (event, next, current) {
      $location.path();// how to access to previous url where the user from ?
                       // how to use event, next and current to get the user last
                      // path on my site, and how to determine the last site is
                      // on my site but not other website ?  
    });

      })

谢谢你的帮助

可能不是最好的答案,但我使用cookie来解决这个问题-因此,每当我重定向到一个新位置时,我都会使用
$cookies.logindestinition=$location.path()
,然后每当用户登录时,我都会使用类似于:

var loginDestination = $cookies.loginDestination || '/';
$cookies.loginDestination = null;
$location.path(loginDestination);

文本中的第一行代码是
$cookie
,而不是
$cookies