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

Can't access state when using resolve #3548

Closed simkessy closed 6 years ago

simkessy commented 6 years ago

This is a:

My version of UI-Router is: (0.2.18)

Hi,

I'm trying to use the resolve feature for states in my application:

        .state('home', {
            url: '/home',
            templateUrl: 'home.html',
            controller: 'homeController',
            resolve: {
                access: function(AuthService) {
                    console.log('statehome')
                    return AuthService.getAccess();
                }
            }
        })

Then in my homeCtrl based on access result from the resole I'll initiate the controller or re-direct

  app.controller('homeController', function ($scope, $timeout, $state, UserService, GroupService, SiteService, HomeService, AuthService, access) 

// Check access: if true init route, else go to settings
if(access) {
    Collections.init();
} else {
    $state.go('settings');
}

Currently as it is, the first time I access the home state it works fine, when I go to a different state, I cannot return to the home state for some reason.

There's no error, nothing happens in the console or network, I have to refresh to be able to get back into the home page.

christopherthielen commented 6 years ago

Your resolve looks OK. There's not enough information provided to answer any question. Version 0.2.18 is very old. You should add $stateChangeError event handler and see if there are any errors.

Closing for two reasons: 1) 0.2.18 is not being supported and 2) you should provide enough information to reproduce an issue such as a plunker, as was mentioned in the issue template