I recently came across an interesting case in one of my Angular projects. Navigating to the site was causing an infinite loop if the app wasn’t configured correctly. The offending piece of code was making use of
$urlRouterProvide provided by the
The issue is that whenever a state fails to resolve it will continuously go to the
otherwise state which just so happened to be the one failing to resolve, infinite loop.
$stateChangeError event thrown whenever a state’s resolve fails, I made it go to a 500 state.
$urlRouterProvider.otherwise for anything other than a 404 state.
Though either step would have fixed the issue having both allows me to handle invalid navigation with 404 state and any state resolving issues with a 500 error.