How to restrict the page from redirect after login/ logout in Angularjs?
<p>I need to restrict the user from redirect and need to login only with authentication.</p>

<p>I tried but I can redirect to login page using back button and again come to same page using forward button. Even I can go to the required page using URL without login.</p>

<p><strong>My code :</strong></p>

<pre><code>config.$inject = ['$routeProvider', '$locationProvider'];
    function config($routeProvider, $locationProvider ) {

        $routeProvider

            .when('/login', {
                controller: 'LoginController',
                templateUrl: 'view/login.view.html',
                controllerAs: 'vm'
            })

            .when('/profileData', {
                controller: 'profileDataController',
                templateUrl: 'view/profiledata.view.html',
                controllerAs :'vm'
            })

            .when('/questionBank', {
                controller: 'questionbankController',
                templateUrl: 'view/questionbank.view.html',
                controllerAs: 'vm'
            })

            .when('/dashboard', {
              //  controller: 'PersonalInfoController',
                templateUrl: 'view/dashboard.view.html',
                controllerAs:'vm'
            })

            .otherwise({ redirectTo: '/login' });

    }

    run.$inject = ['$rootScope', '$location', '$cookieStore', '$http'];
    function run($rootScope, $location, $cookieStore, $http) {
        // keep user logged in after page refresh
        $rootScope.globals  = $cookieStore.get('globals') || {};


        if ($rootScope.globals.currentUser) {
            $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
        }

         $rootScope.$on('$locationChangeStart', function (event, next, current) {
            //redirect to login page if not logged in and trying to access a restricted page

             var restrictedPage = $.inArray($location.path(), ['/dashboard','/questionBank', '/profileData']) === -1;

/*            var a    = $location.$$absUrl.split('#')[1];
              var patt = new RegExp(a);
              var res  = patt.test(restrictedPage); */

              var loggedIn = $rootScope.globals.currentUser;

            if (restrictedPage &amp;&amp; !loggedIn) {
                $location.path('/login');

            }  
        }); 
}
</code></pre>