Is there a way to avoid the double loading of routes in AngularJS when trying to dynamically load a route based on a user's most recent visit to a child route? Currently, I am using onEnter but it causes the parent route to load first and then a second load happens to load the child route. Can we prevent this second load and directly go to the child route if the necessary information is already available?
(function() {
'use strict';
angular
.module('curation')
.config(routesConfig);
routesConfig.$inject = ['$stateProvider'];
/**
* Route Configuration to define URL patterns for the module
* @param {Function} $stateProvider
*/
function routesConfig($stateProvider) {
// Curation state routing
$stateProvider.
state('site.curation', {
url: '/curation',
templateUrl: 'modules/curation/views/curation.client.view.html',
resolve: {
publicFronts: function($stateParams, frontsService) {
return frontsService.getPublicFronts($stateParams.siteCode);
},
authoringTypes: function(assetMetadata) {
return assetMetadata.authoringTypes().then(function(value) {
return value.data.authoringTypes;
});
}
},
onEnter: function($state, $timeout, userSitePreferences, publicFronts) {
$timeout(function() {
var recentFront = _.find(publicFronts, {
Id: userSitePreferences.curation.recentFrontIds[0]
});
if (recentFront) {
$state.go('site.curation.selectedFront.selectedLayout', {
frontId: recentFront.Id,
layoutId: recentFront.LayoutId
});
}
});
}
});
}
})();