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

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

    1. First, add a property to the 'manager.staffDetail.view' state of abstract:true. This isn't required, but you want to set this since you'd never go to this state directly, you'd always go to one of it's child states.

    2. Then do one of the following:

      • Give the 'manager.staffDetail.view.schedule' state an empty URL. This will make it match the same url as it's parent state url, because it appends nothing to the parent url.

        .state('manager.staffDetail.view.schedule', {url:'', ...

      • Or if you want to keep the url of the default child route unchanged, then set up a redirect in your module.config. This code here will redirect any location of '/staff/{id}/view' to the location of '/staff/{id}/view/schedule':

        $urlRouterProvider.when('/staff/{id}/view', '/staff/{id}/view/schedule');

提交回复
热议问题