ui-router: default route based on user role

后端 未结 2 1437
生来不讨喜
生来不讨喜 2021-02-09 19:09

I\'m using UI router in my project. The home page of my application consists of 4 tabs, each routing to a different template. This is my current routing code, im using a forEach

2条回答
  •  情书的邮戳
    2021-02-09 20:15

    I already have had to solve that :

    I've registered a state that was used only to handle the default page based on the role.

            $urlRouterProvider.otherwise("/");
            $stateProvider.state("default", {
                url:"/",
                templateUrl: "app/core/home/default.html",
                controller: "DefaultController"
            });
    

    The the controller was simply :

    (function () {
        "use strict";
    
        angular.module("core").controller("DefaultController", [
            "$rootScope",
            "$state",
            "roles",
            function ($rootScope, $state, roles) {
                if ($rootScope.hasPermission(roles.SomeRoleName)) {
                    $state.go("someStateName");
                } else if ($rootScope.hasPermission(roles.SomeRoleName)) {
                    $state.go("someStateName");
                }
            }
        ]);
    })();
    

提交回复
热议问题