While using ui-router i tried for resolve , is there any accesstoken in localstorage , if so proceed to state 'home' else state 'login'. But the program doesnt run as desired, if there is no accesstoken and i hit url for my view page, it shows blank page(i think my view page) not loading login.
here is the part
$stateProvider
.state("home", {
url: "/home",
templateUrl: "home.html",
resolve: {
"check": function() {
console.log("/home");
if (localStorage.getItem("accessToken") == null) {
console.log("main check");
$state.go("login");
}
}
}
})
.state("login", {
url: "/login",
templateUrl: "loginpage.html",
resolve: {
"check": function() {
console.log("/login");
if (localStorage.getItem("accessToken") != null) {
console.log("log check");
$state.go("home");
}
}
}
})
.state("otherwise", {
url: "*path",
templateUrl: "loginpage.html",
resolve: {
"check": function() {
console.log("/login");
if (localStorage.getItem("accessToken") != null) {
console.log("log check");
$state.go("home");
}
}
}
});
console prints "log check" but shows no page... please help