0

是否可以根据解析器结果“停止”状态构建?例如,我有以下代码:

    /**
 * @author v.lugovsky
 * created on 16.12.2015
 */


(function() {
    'use strict';

    angular.module('BlurAdmin.pages.dashboard', [])
        .config(routeConfig);

    /** @ngInject */
    function routeConfig($stateProvider) {

        $stateProvider
            .state('dashboard', {
                resolve: {
                    user: function(baSidebarService){
                        if(baSidebarService.getStorage()){
                            return
                        }
                    }
                },
                // if baSidebarService.getStorage() == true
                url: '/dashboard',
                templateUrl: 'app/pages/dashboard/dashboard.html',
                title: 'Dashboard',                
                sidebarMeta: {
                    icon: 'ion-android-home',
                    order: 0,
                },
            });
    }

})();

如果没有安装真正的返回,我希望它能够解决,即隐藏菜单项、导航、图标等。

4

1 回答 1

0

要从解析函数中止状态更改,请返回被拒绝的承诺抛出原因:

app.config(routeConfig);

/** @ngInject */
function routeConfig($stateProvider) {

    $stateProvider
        .state('dashboard', {
            resolve: {
                user: function(baSidebarService){
                    if(baSidebarService.getStorage()){
                        return
                    }
                    //ELSE abort state change
                    throw "no user";
                }
            },
            // if baSidebarService.getStorage() == true
            url: '/dashboard',
            templateUrl: 'app/pages/dashboard/dashboard.html',
            title: 'Dashboard',                
            sidebarMeta: {
                icon: 'ion-android-home',
                order: 0,
            },
        });
}
于 2019-05-02T15:00:23.567 回答