我有一个非常简单的要求。
我有 3 个用户角色:
- 猫用户
- 许可用户
ALLUSER
- 我在
$rootScope.userRole
变量中有用户角色的值。 - 我在 AngularJS 应用程序启动之前已经定义了用户角色,因为 AngularJS 应用程序是从 PHP 脚本调用的,并且用户角色已经在 PHP 脚本中定义。
- 我在
现在,当 AngularJS 应用程序启动时,根据角色我想拥有以下路由:
$rootScope.userRole == "CATUSER"
if ($rootScope.userRole == "CATUSER") {
$routeProvider
.when("/catheter", {
title: "Catheter Expiration Code Generator",
templateUrl: "app/catheter/catheter.html",
controller: "CatheterController",
controllerAs: "vm"
})
.when("/support", {
title: "Support",
templateUrl: "app/support/support.html",
controller: "SupportController",
controllerAs: "vm"
})
.otherwise({
redirectTo: "/catheter"
});
}
$rootScope.userRole == "LICUSER"
if ($rootScope.userRole == "LICUSER") {
$routeProvider
.when("/license", {
title: "License Generator",
templateUrl: "app/license/license.html",
controller: "LicenseController",
controllerAs: "vm"
})
.when("/support", {
title: "Support",
templateUrl: "app/support/support.html",
controller: "SupportController",
controllerAs: "vm"
})
.otherwise({
redirectTo: "/license"
});
}
$rootScope.userRole == "ALLUSER"
if ($rootScope.userRole == "LICUSER") {
$routeProvider
.when("/license", {
title: "License Generator",
templateUrl: "app/license/license.html",
controller: "LicenseController",
controllerAs: "vm"
})
.when("/catheter", {
title: "Catheter Expiration Code Generator",
templateUrl: "app/catheter/catheter.html",
controller: "CatheterController",
controllerAs: "vm"
})
.when("/support", {
title: "Support",
templateUrl: "app/support/support.html",
controller: "SupportController",
controllerAs: "vm"
})
.otherwise({
redirectTo: "/license"
});
}
我不想使用 UI 路由器。