Link 1 Link 2
I am trying to get current URL in alert but I guess angular script is running first before alert, so when I click link 2 its showing link 1 and vice versa. Is there anything i am missing or is there a to get URL of the page after page is loaded in angularjs 1.7
(function () {
    var app = angular.module('myApp');
    app.controller('initiativesController', ['$scope',
      function ($scope) {
          $scope.TestInitiatives = "Test";
          var url = window.location.pathname.split('/')[1];;
          alert(url)
          console.log($scope.TestInitiatives);
      }
    ]);
})();
Angular app.js
(function () {
    var myapp = angular.module('myApp', ["ui.router"]);
    myapp.config(function ($stateProvider, $locationProvider, $urlRouterProvider) {
        // For any unmatched url, send to /route1
        $urlRouterProvider.otherwise("/route1")
        $stateProvider
          .state('route1', {
              url: "/route1",
              templateUrl: "SOC/Views/route1.html",
              controller: "route1ctrl"
          })
          .state('route2', {
              url: "/route2",
              templateUrl: "SOC/Views/route2.html",
              controller: "route2ctrl"
          })
        $locationProvider.html5Mode({
            enabled: true,
            requireBase: false
        });
    });
})();