我正在转向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');
<a href="#/app"> // will be redirected to state1 <a href="#/app/state1"> <a href="#/app/state2">
abstract
(optional)boolean
An abstract state will never be directly activated,but can provide inherited properties to its common children states.
检查它here