Change location if LocalStorage value is null

I have a login page. After login I store the user value into session storage like

localStorage.setItem("user", something);

After successful login I change the $location.path('/something'). In this page I assign $scope.user=localStorage.getItem("user"). If suppose user delete the history and reload the successful login page (/something) I getting error.

I tried like:

if (!localStorage.getItem("user")) {
    $scope.$apply(function(){
        $location.path('/');
    })
}

But it’s not working. How can I solve this?


Source: html5

Leave a Reply