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?

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.