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

前端之家收集整理的这篇文章主要介绍了angularjs – UI-Router:阻止访问父状态前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在转向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

猜你在找的Angularjs相关文章