Angular angular-ui-router access error angular 1.6.5

641 Views Asked by At

I am trying to reject access to a view if no cookie is set, I keep getting same errors in my console on reject. resolve works fine but reject gives errors. I have looked around and found a few threads and answers but non have yet helped some said this problem was fixed in 1.61 but im still getting it.

My code

 .state('form.mockup', {
        url: '/mockup',
        templateUrl: 'views/form-mockup.html',
        resolve: {
            "check": ['$q', '$cookies', '$location', function($q, $cookies, $location) {
                if ($cookies.get('UserName')) { //cookie to check
                    console.log("logged in");
                    return $q.resolve({});
                } else {
                    console.log("error no access");
                    return $q.reject('no access allowed');
                    $location.path('/form/upload');

                }
            }
        ]
        }
    })

My error

Transition Rejection($id: 3 type: 6, message: The transition errored, detail: no access allowed) _defaultErrorHandler @ angular-ui-router.min.js:13 (anonymous) @ angular-ui-router.min.js:13 (anonymous) @ angular.js:17000 $digest @ angular.js:18182 $apply @ angular.js:18480 (anonymous) @ angular.js:20397 e @ angular.js:6362 (anonymous) @ angular.js:6642

Possibly unhandled rejection: {"$id":3,"type":6,"message":"The transition errored","detail":"no access allowed"} (anonymous) @ angular.js:14642 (anonymous) @ angular.js:11102 g @ angular.js:17028 $digest @ angular.js:18182 $apply @ angular.js:18480 (anonymous) @ angular.js:20397 e @ angular.js:6362 (anonymous) @ angular.js:6642

0

There are 0 best solutions below