Search code examples
angularjsangular-ui-routerangularjs-rootscope

rootscope getting reset when i change url directly from browser


I am using ui-router and states. When user logs in in rootscope i add a variable called profile and push in the logged in details. When i change state from UI i.e. clicking on a link rootscope.profile stays on, but if i change url directly rootscope.profile says undefined? What may be the exact reason.

Here is my state

 $stateProvider
    .state('root', {
      abstract : true,
      views : {
          '' : {templateUrl : "views/home/root.html"},
          'topbar@root' : {
              templateUrl: "views/menu/topbar.html",
              controller: "TopBarCtrl"                
          },
          'menu@root' : {
              templateUrl: "views/menu/nav.html",
              controller: "NavCtrl"                
          },
          'footer@root' : {
              templateUrl: "views/footer/footer.html",
              controller: "FooterCtrl"                
          } 
      }      
    })
    .state('mypage', {
      parent : 'root',
      url: "/mypage",
      templateUrl: "views/mypage/mypage.html",
      controller: "mypageCtrl",
      data : {
          authorizedRoles : [mypage_ROLES.PUBLIC]
      }

    }).config(function($locationProvider){
    $locationProvider.html5Mode(true).hashPrefix('!');
});

Here is my nginx server settings

 server {
        listen 8000;
        root C:/xampp/htdocs/myapp/myapp/app;
        index index.html index.htm;
        server_name localhost;
        location / {
           try_files $uri /index.html;

        }
        }

In my index.html i have like

<base href="/">

Solution

  • This is Single Page Application.When you change url directly,it's means that you open a new application, so rootscope.profile is undefined.