我有4种状态:dashboard,dahboard.main,dashboard.minor,login.仪表板是抽象的,它是.minor和.main状态的父状态.以下是我的代码:
.state('dashboard', {
url: "/dashboard",
abstract: true,
templateUrl: "views/dashboard.html",
resolve: {
auth: function ($q, authenticationSvc) {
var userInfo = authenticationSvc.getUserInfo();
if (userInfo) {
return $q.when(userInfo);
} else {
return $q.reject({ authenticated: false });
}
}
},
controller: "DashboardCtrl",
data: { pageTitle: 'Example view' }
})
.state('dashboard.main', {
url: "",
templateUrl: "views/main.html",
controller: "DashboardCtrl",
data: { pageTitle: 'Main view' }
})
Run Code Online (Sandbox Code Playgroud)
正如您在仪表板状态中看到的,我有解决方案选项.如果他没有被授权,我想将用户重定向到登录页面.出于这个原因,我使用特殊的authenticationSvc服务:
.factory("authenticationSvc", ["$http", "$q", "$window", function ($http, $q, $window) { …Run Code Online (Sandbox Code Playgroud)