1

Working with Angular and im running into a few issues using $location.url & $location.path

The URL changes at the top of the page to /users/sign_in but I don't see the view until I manually refresh the page, then it appears?

function error(response) {
            if (response.status == 401) {
                $rootScope.$broadcast('event:unauthorized');
                $location.url('/users/sign_in');
            };
        };

I am not getting any errors.

4
  • 1
    Did you try with $location.path('/users/sign_in');? Commented Feb 2, 2014 at 0:06
  • 2
    $location.path, not url should do the trick Commented Feb 2, 2014 at 0:09
  • Same thing happens using either .path or .url Commented Feb 2, 2014 at 0:11
  • Are you sure there isnt any message on console of browser? Commented Feb 2, 2014 at 0:18

1 Answer 1

1

You're doing a bit too much in your function. You're attempting to change the URL but also return a response. You can try using a $scope.$apply() right after the $location.url call, however you should consider splitting this logic so that the redirect occurs based on the returned response, or don't return any response from the error function.

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

1 Comment

Having the same problem. Any advice?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.