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

  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');`
    

Leave a Comment