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

前端 未结 9 700
忘掉有多难
忘掉有多难 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:24

    here is a very simple and transparent alternative by just modifying parent state in ui router:

      .state('parent_state', {
        url: '/something/:param1/:param2',
        templateUrl: 'partials/something/parent_view.html',  // <- important
        controller: function($state, $stateParams){
          var params = angular.copy($state.params);
          if (params['param3'] === undefined) {
            params['param3'] = 'default_param3';
          }
          $state.go('parent_state.child', params) 
        }
      })
    
      .state('parent_state.child', {
        url: '/something/:param1/:param2/:param3',
        templateUrl: '....',  
        controller: '....'
      })
    

提交回复
热议问题