0

I feel a bit silly for asking this, I've looked and searched for this for quite a few hours and know the two main methods for setting up default child states is to:

 url: '',
 or 
 $urlRouterProvider.when('/route', '/newroute');

I'm trying to use the empty url config as the reroute option causes unwanted issues when the parent state is set to abstract: true. All templates contain a ui-view element(s). My code looks similar to this at the moment:

       .state('data', {
            url: "/data",
            templateUrl: "views/data.php",
        })
        .state('data.overview', {
            url: "",
            templateUrl: "views/subviews/data.overview.php",
        })
        .state('data.overview.view', {
            url: "",
            templateUrl: "views/subviews/subviews/data.overview.view.php"
        })
        .state('data.overview.view.msgfav', {
            url: "",
            views: {
                msg: {
                    templateUrl: "views/subviews/subviews/data.overview.view.msg.php"
                },
                fav: {
                    templateUrl: "views/subviews/subviews/data.overview.view.fav.php"
                }
            }
        })

As well as some more child states (which didn't seem relevant to include since not meant to be default). I've tried with the parent state as abstract: true and without setting it, with url empty and no url setting at all, with only the closest child state and not all nested. Sticking an ng-include in there can work as default state, but it feels unclean.Targeting each child directly works fine. I'm really not sure what I'm missing here, but I'm sure it's some small detail that will make me look silly.

bjoops
  • 11
  • 4

1 Answers1

0

I'm not sure whether I should reply with an answer to my own question, but think that's appropriate.

I don't think you can target the parent state (abstract) directly in ui-sref and expect it to default to child state and populate the view, but rather target the child state in links. Then have to set every parent state down the chain to abstract down to the point you want populated automatically. I didn't find this completely clear, and one part of the answer in this post threw me off a little on that;

"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."

angularjs ui-router default child state

bjoops
  • 11
  • 4