2016-08-03 72 views
0

以下是我的ui-router配置。 '家'是父母国家,'批'是许多其他儿童的状态。

//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'状态时将用户重定向到'batch'状态。 我正在尝试以下来实现,但它不工作。

$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 
    } 
    }); 
+1

我很困惑。你想让批次与家一起展示还是永远不要在家中展示? –

+0

'if'检查通过了吗?你注入了'$ location'吗? – Marko

+0

你想'家'是'抽象'。参见路由器文档。创建一个你的问题plunker演示 – charlietfl

回答