以下是我的ui-router配置。 'home'是父状态,'批次'是其中许多子状态。
//config
.state('home',{
url:'/home',
templateUrl:'../views/sidenav/home.htm',
controller: 'homeController',
controllerAs: 'home'
})
.state('batches',{
parent:'home',
url:'/batches',
templateUrl:'../views/sidenav/batches.htm',
controller: 'batchesController',
controllerAs: 'batches'
})
问题是'home'除侧面导航栏外有一个空视图。因此,我希望它在用户尝试进入“主页”状态时将用户重定向到“批处理”状态。 我正在尝试以下方法来实现这一点,但它无法正常工作。
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
if(toState.name=='home'){ //home is a parent state
$location.path('/home/batches'); //batches is a child state of home
}
});
答案 0 :(得分:0)
将你的家庭状态设置为抽象,抽象状态将使用导航栏设置htm。
检查ui-router wiki。
https://github.com/angular-ui/ui-router/wiki/Nested-States-and-Nested-Views
并检查$ location的dependecy注入