How to redirect to another page in routeProvider in resolution mode
I want to redirect mypage to home page if sessionStorage.logged is set to true. Below is my code. why is my below code not working.
Since I'm new to angularjs I don't know how to do this. I will be more grateful to you if you can help solve this problem.
.when('/login',
{
templateUrl: 'views/login.html',
controller:'LoginCtrl',
resolve:
{
mess:function()
{
var t=(sessionStorage.logged).toString();
if(t=="true")
{
redirectTo: '/home';
}
}
}
})
+3
source to share
1 answer
Use it $location.path()
, it works the same as redirectTo
:
.when('/login',
{
templateUrl: 'views/login.html',
controller:'LoginCtrl',
resolve:
{
mess:function($location)
{
var t=(sessionStorage.logged).toString();
if(t=="true")
{
$location.path('/home');
//redirectTo: '/home';
}
}
}
})
+5
source to share