加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – UI-Router:阻止访问父状态

发布时间:2020-12-17 17:21:03 所属栏目:安全 来源:网络整理
导读:我正在转向UI-Router作为我的App路由器.我想嵌套状态如下: $stateProvider.state('app',{ url: '/app',template: ' div ui-view/div',authenticate: true }).state('app.state1',{ url: '/state1',templateUrl: 'app/state1.html',controller: 'State1Ctrl'
我正在转向UI-Router作为我的App路由器.我想嵌套状态如下:

$stateProvider
.state('app',{
      url: '/app',template: ' <div ui-view></div>',authenticate: true
    })
.state('app.state1',{
      url: '/state1',templateUrl: 'app/state1.html',controller: 'State1Ctrl',controllerAs: 'state1',authenticate: true
    })
.state('app.state2',{
      url: '/state2',templateUrl: 'app/state2.html',controller: 'State2Ctrl',authenticate: true
    })

我的$state叫app是其他人的父母.它只包含一个< div ui-view>< / div>模板.它不应该直接访问.我的意思是如果用户在URL中输入/ app,他们应该被重定向到`app.state1“

如何阻止我的用户这样做?

解决方法

有 a working example

让你的州抽象:

.state('app',abstract: true,// here
      template: ' <div ui-view></div>',authenticate: true
    })

并添加一些默认重定向:

$urlRouterProvider.when('/app','/app/state1');
  $urlRouterProvider.otherwise('/app/state1');

下面的前2个链接将重定向到’app.state1′

<a href="#/app"> // will be redirected to state1
<a href="#/app/state1">
<a href="#/app/state2">

doc about $stateProvider:

abstract (optional) boolean

An abstract state will never be directly activated,but can provide inherited properties to its common children states.

检查它here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读