Opening link in new browser redirecting me to login page in Angular JS

Issue

I have AngularJS website which contains few hyperlink. Whenever I try to open the link in same tab then it is working fine but whenever I try to open the link in new tab then it is redirecting me to login page.

RouteController.js

var app = angular.module("appHome", ['ui.router']);

app.config(function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/login');
    $stateProvider
        .state('introduction', {
            url: '/',
            views: {
                'mainview':
                {
                    templateUrl: 'HomeLoginPages/Login.html',
                    controller: 'ctrlLogin'
                }
            }
        })
        .state('login', {
            url: '/login',
            views: {
                'mainview':
                {
                    templateUrl: 'HomeLoginPages/Login.html',
                    controller: 'ctrlLogin'
                }
            }
        })
        .state('home.eventlist.requestdetail', {
            url: '/requestdetail',
            params: { paramOne: "defaultValueOne", paramTwo: "defaultValueTwo", paramThree: "defaultValueThree", paramFour: "defaultValueFour" },
            views: {
                'homedetailview@home':
                {
                    templateUrl: 'RequestPages/DetailedRequest.html',
                    controller: 'ctrlRequestDetail',

                }
            }
        })
})

HTML File

<form class="form-main">
    <div class="div-main">
        <div class="gridBigStyle" ui-grid="gridEventList" ui-grid-pagination>
        </div>
    </div>
</form>

Controller.js

var myApp = angular.module('appHome');
myApp.controller("ctrlEventList", ['$scope', 'MetadataOrgFactory', function ($scope, MetadataOrgFactory) {
    $scope.gridEventList = {
        data: 'eventlistdata',     
        columnDefs: [
            { field: 'SiteEventNumber', displayName: 'Event Number' },
            {
                field: 'RequestNumber', displayName: 'Event Request',
                cellTemplate: '<a ui-sref=".requestdetail({paramOne:row.entity.RequestId, paramTwo:row.entity.EventId, paramThree: 1,paramFour: defaultValueFour})" class="ui-grid-cell-contents">{{COL_FIELD}}</a>'
            },
        ]
    }
}]);

I am using Token Authentication during login of user. The token is valid always but it is still redirecting me to Login Page.

Solution

I have saved the login information in localstorage variable which is used in all tabs. When user log out then I have explicitly set the value to blank so that all other tabs page will be redirect to login page. I hope this answer will help others.

Answered By – simple user

Answer Checked By – Clifford M. (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.