Directing the user to a child state when they are transitioning to its parent state using UI-Router

前端 未结 9 701
忘掉有多难
忘掉有多难 2020-11-30 19:06

Consider the following:

.state(\'manager.staffList\', {url:\'^/staff?alpha\', templateUrl: \'views/staff.list.html\', data:{activeMenu: \'staff\'}, controlle         


        
9条回答
  •  心在旅途
    2020-11-30 19:32

    This is late but all the answers here don't apply to the latest version of angular-ui-router for AngularJS. As of that version (specifically @uirouter/angularjs#v1.0.x you can just put redirectTo: 'childStateName' in the second param of $stateProvider.state(). For example:

    $stateProvider
    .state('parent', {
      resolve: {...},
      redirectTo: 'parent.defaultChild'
    })
    .state('parent.defaultChild', {...})
    

    Here is the relevant doc section: https://ui-router.github.io/guide/ng1/migrate-to-1_0#state-hook-redirectto

    Hopefully this helps someone!

提交回复
热议问题