Reputation: 1923
ui-router breaks when minifying if the code isn't annotated properly. I have done this and most of my routes work, but this in particular does not:
var authRedirect = function(s) {
return ['$state', '$q', 'AuthService', function($state, $q, AuthService) {
var d = $q.defer();
var is_auth = AuthService.checkAuth();
if(!is_auth) {
d.reject();
$state.go(s);
} else
d.resolve();
return d.promise;
}];
}
// ...
.state('secret', {
url: '/secret',
controller: 'TestCtrl',
templatesUrl: '/test.html',
resolve: { authRedirect: authRedirect('other') }
})
.state('other', { .... } )
I'm passing in another state into my resolve
function, which should redirect to that state if some condition isn't met. I use this resolve function in several other routes, so it's a handy way of keeping the ui-router code clean.
While the non-minified version is working fine, the minified version of this doesn't work (it does nothing). But it seems like I've annotated it properly since no errors were thrown. What could be wrong?
Upvotes: 3
Views: 335
Reputation: 28475
You can also try by updating the code like this
.state('secret', {
url: '/secret',
controller: 'TestCtrl',
templatesUrl: '/test.html',
resolve: { authRedirect: function() { return authRedirect('other')} }
})
Upvotes: 0
Reputation: 28475
Please update the code with
.state('secret', {
url: '/secret',
controller: 'TestCtrl',
templatesUrl: '/test.html',
resolve: { authRedirect: ['authRedirect', function(authRedirect){ return authRedirect('other')}] }
})
Upvotes: 1