javascript - Handling page refresh in angular ui-router -


when ever reload/refresh page, state routes root page. when checked value of $state.current after reload empty.

currentstate:

object {name: "", url: "^", views: null, abstract: true} 

states:

angular.module('app', ['ngcookies','ngresource','ui.router']) .config(function ($stateprovider, $urlrouterprovider) {  $stateprovider     .state('login', {         url: '/login',         templateurl: "views/login.html",         data: {             required: false         }     })     .state('dashboard', {         url: '/dashboard',         templateurl: "views/dashboard.html",         data: {             required: true         }     }); $urlrouterprovider.otherwise('/login'); })  .run(["$rootscope", "$state", "$location", "authservice", "$cookies", "$sessionstorage", function ($rootscope, $state, $location, authservice, $cookies, $sessionstorage) { $rootscope.$on('$statechangestart', function (e, tostate, toparams, fromstate, fromparams) {     console.log("currentstate: ", $state.current);     console.log("tostate is:", tostate);      if (tostate.data.required && !$sessionstorage.authuserid) {         alert("state not authenticated");         e.preventdefault();         $state.go('login');     } }); }]); 

why value of current state becomes empty on refresh?


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -