angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

how capture route error $stateChangeError ? #3531

Closed GlauberF closed 4 years ago

GlauberF commented 7 years ago

I'm trying to capture the error, but they're not getting it.

code in my route: resolve: { login: function($q, $auth) { if ($auth.isAuthenticated()) { return true; } else { var errorObject = { code: 'NOT_AUTHENTICATED' }; return $q.reject(errorObject); } } }

code no .run: `$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { event.preventDefault()

$timeout(function() {
    $state.go('app.auth_entrar');
    console.log(event, toState, toParams, fromState, fromParams, error);
});

})`

answer on error: erro

where I should receive the error that I created, I get an error from angularjs, where am I wrong ??

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.