OHope
OHope

Reputation: 618

Angularjs - $location.path / $location.url changes URL but doesn't refresh page

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.

Upvotes: 1

Views: 8032

Answers (1)

Mendhak
Mendhak

Reputation: 8775

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.

Upvotes: 1

Related Questions