简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM