0

i am working in AngularJs and i have a problem.

When the user push the login button, the page go back to the previous page, but i only want go back if one of the routeprovider page and go to "/" route if teh previous page is another page. Actualy i use:

       if (history.length > 1)
        {
            history.back();
        }
        else
        {
            $location.url("/");
        }

How can i see the previous page url and compare it?

jorgeregidor
  • 208
  • 2
  • 13

2 Answers2

1

JavaScript allows navigation based on window.history, but it does not allow reading the actual history. So you cannot check the previous URL.

You may want to try document.referrer to check the previous URL (before entering the AngularJS app, I presume, as after entering you do not reload the page).

You may also build your history manually in AngularJS to see whether you have previously been navigating through your application: angularjs getting previous route path

Community
  • 1
  • 1
mingos
  • 23,778
  • 12
  • 70
  • 107
1
$scope.$on('$routeChangeStart', function(next, current) { 
  ... you could trigger something here ...
});

Please refere to $routeChangeStart of angular which might help you for your query.

micronyks
  • 54,797
  • 15
  • 112
  • 146