简体   繁体   English

在 Angularjs 中,如何阻止用户接近某些页面?

[英]In Angularjs, how to block user approaching to some pages?

I'm using ui-router and $stateProvider to show views.我正在使用ui-router$stateProvider来显示视图。

This project is for building admin page, and there are three accounts.该项目用于构建管理页面,共有三个帐户。

My purpose is some pages must be shown to each accounts only.我的目的是某些页面必须只显示给每个帐户。

So, I've used ng-if to not show on nav-bar , it was successful.所以,我使用ng-if不显示在nav-bar ,它成功了。

But if typed its url and approached directly, these pages were shown.但是如果输入它的 url 并直接接近,这些页面就会显示出来。

Are there any way to make branch in `configs'?有没有办法在“配置”中创建分支? or other ways to solve this?或其他方法来解决这个问题?

I think this question does not need to post fiddle or plunker,我认为这个问题不需要张贴小提琴或 plunker,

so I've just put my code of configs .所以我只是把我的代码configs

$urlRouterProvider.otherwise('/admin/login');
$stateProvider
.state('root.for_a', {
    url: '/:brand_id/for_a',
    views: {
        'appContainer@': {
            templateUrl: 'views/for_a.html',
            controller: 'ForACtrl',
        }
    }
})
.state('root.for_b', {
    url: '/:brand_id/for_b',
    views: {
        'appContainer@': {
            templateUrl: 'views/for_b.html',
            controller: 'ForBCtrl',
        }
    }
})
.state('root.for_c', {
    url: '/:brand_id/for_c',
    views: {
        'appContainer@': {
            templateUrl: 'views/for_c.html',
            controller: 'ForCCtrl',
        }
    }
})

I'll wait any handsome or pretty programmers can help me.我会等待任何英俊或漂亮的程序员可以帮助我。 :) :)

Thanks in advance.提前致谢。

What I did to overcome similar issue was, use 'ng-if' on 'ui-view' tags.我为克服类似问题所做的是在“ui-view”标签上使用“ng-if”。

 <ui-view ng-if="functionToEvaluatePermissions()"></ui-view>
 <span ng-if="!functionToEvaluatePermissions()"> You shouldn't be here. </span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM