You have already found a solution for me. Indeed, as stated in your code:
$urlRouterProvider.when('/', '/profile/x/details');
The default URL is /profile/x/details . When ui-router sees this url, it will try to load the state hierarchy: base , base.profile et base.profile.details . As you said, the latter will not be downloaded, since you will catch the 404 error and redirect the request to another location.
The problem is that you are still in /profile/x/details . So, in stateChangeError , when you executed $state.go('404', null, { location: false }); ui-router will check the url.
Since it is not set to 404 , it will take the one that it has: /profile/x/details . And that is why it allows the same hierarchy of states: base , base.profile et base.profile.details .
Zakaria
source share