Feature: Default sub-state for abstract states
See original GitHub issueAs per this discussion: https://github.com/ProLoser/AngularJS-ORM/issues/12
It would be cool if abstract states could have a default sub-state. Lets say project
is an abstract state. However, instead of being unable to go directly to it, if you DO go directly to it, you automatically get pushed into a substate (such as project.tasks
). This should probably handle either a string or an injectable callback function.
Otherwise I have to do crap like this:
function ProjectController($scope, $state) {
$scope.$on('$stateChangeSuccess', function(event, toState) {
if (toState.name === 'project') {
$state.go('.tasks');
}
});
}
If you simply do the check once when the controller loads, then going from project.whatever
to project
doesn’t re-execute the controller and therefore the check isn’t performed again. If you put this logic earlier (such as in a resolve
or onEnter
) then the (async?) call to $state.go
will restart the entire resolve resolution process since the route never finished loading, which causes an endless loop (unless you add toState checks in, yadda yadda).
Long story short, I think this is an excellent idea and I approve this message.
Issue Analytics
- State:
- Created 9 years ago
- Comments:42 (15 by maintainers)
@inca I can’t speak to when this feature will be added. But in the meantime you could use the implementation I described in #1584.
We’ve been using this for a while and it works great.
in #1584 @acollard said:
@acollard That’s pretty close to what I’m thinking. In ui-router-extras I’ve added a similar option for default substate, using
default
for the key and { state: “”, params: {} } as the value.