如果我在 angular JS 中登录后单击后退按钮,如何重定向到主页?
How to redirect to home page if I click back button after login in angular JS?
.run(['$rootScope', '$location', 'Auth','$state', function ($rootScope, $location, Auth,$state) {
$rootScope.$on('$routeChangeStart', function (event) {
if (!Auth.isLoggedIn()) {
console.log('DENY');
event.preventDefault();
$state.go('login');
}
else {
console.log('ALLOW');
$state.go('dashboard.admin');
}
});
}])
$rootScope.$on('$routeChangeStart', function (event) {
if (!Auth.isLoggedIn()) {
console.log('DENY');
event.preventDefault();
$state.go('login');
}
else {
console.log('ALLOW');
if($state.includes('login')) {
event.preventDefault();
}
$state.go('dashboard.admin');
}
});
您可以使用
$window.location.href = "homePageUrl";
示例:
$window.location.href = "index.html";
或者您可以使用 angularJs 的 $location 服务
Link:$location。
在您想要加载主页的任何情况下使用它,
假设您正在维护会话状态
希望能帮助到你
问候
肖希尔
这取决于您为家定义的状态。
$state.go('home');
对您有用的链接是:-
https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views
.run(['$rootScope', '$location', 'Auth','$state', function ($rootScope, $location, Auth,$state) {
$rootScope.$on('$routeChangeStart', function (event) {
if (!Auth.isLoggedIn()) {
console.log('DENY');
event.preventDefault();
$state.go('login');
}
else {
console.log('ALLOW');
$state.go('dashboard.admin');
}
});
}])
$rootScope.$on('$routeChangeStart', function (event) {
if (!Auth.isLoggedIn()) {
console.log('DENY');
event.preventDefault();
$state.go('login');
}
else {
console.log('ALLOW');
if($state.includes('login')) {
event.preventDefault();
}
$state.go('dashboard.admin');
}
});
您可以使用
$window.location.href = "homePageUrl";
示例: $window.location.href = "index.html"; 或者您可以使用 angularJs 的 $location 服务 Link:$location。 在您想要加载主页的任何情况下使用它, 假设您正在维护会话状态 希望能帮助到你 问候 肖希尔
这取决于您为家定义的状态。
$state.go('home');
对您有用的链接是:-
https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views