如果我在登录后复制欢迎页面的URL并在注销后粘贴欢迎页面的URL,它将重定向到登录页面,因为我正在使用本地存储名称进行检查,所以它工作正常。现在的问题是我无法进入注册页面,因为在用户注销以注册新用户时应打开该页面,因为该用户在本地存储中将为空,请有人帮我解决此问题。
这是我申请的路线
app.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
templateUrl : 'app/components/login/login.html',
controller : 'loginCtrl'
}).when('/register/', {
templateUrl : 'app/components/register/register.html',
controller : 'registerController'
}).when('/welcome/', {
templateUrl : 'app/components/dashBoard/dashboard.html',
controller : 'welcomeController'
}).when('/logout', {
templateUrl : 'app/components/login/login.html',
controller : 'LogoutController'
}).when('/forgotPwd', {
templateUrl : 'app/components/forgotPassword/forgotPassword.html',
controller : 'forgotPwdController'
}).when('/changePwd', {
templateUrl : 'app/components/changePwd/changePassword.html',
controller : 'changePwdController'
}).otherwise({
redirectTo : "/"
});
} ]).run(function($rootScope, $location) {
$rootScope.$on( "$routeChangeStart", function(next) {
$rootScope.username = localStorage.getItem("UserName");
//alert("redirecting to login");
if ($rootScope.username === null) {
// no logged user, redirect to /login
if ( next.templateUrl === "app/components/login/login.html") {
} else {
$location.path("/");
}
}
});
});
run(function($rootScope, $location) {
$rootScope.$on( "$routeChangeStart", function(next) {
$rootScope.username = localStorage.getItem("UserName");
//alert("redirecting to login");
if ($rootScope.username == null) {
// no logged user, redirect to /login
if ( $location.$$url == "/" || $location.$$url == "/register/") {
// do nothing. Do not redirect
} else {
// redirect to default path
$location.path("/");
}
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句