Closed GhazanfarKhan closed 5 years ago
$stateProvider.state('store', {
abstract: true,
views: {
content: {
template: "<div ui-view='content'></div>"
}
},
resolve: {
_auth: function (AuthService) {
return AuthService.authenticate()
}
}
}).state('store.product', {
url: '/stores/:storeId/products/:productId/',
views: {
content: {
templateUrl: 'product.html',
controller: 'ProductCtrl'
}
},
resolve: {
_config: function ($transition$) {
const storeId = $transition$.params().storeId
return {
storeURL: `${APP_SETTINGS.ENDPOINT_BASE}/stores/${storeId}/`,
}
},
_store: function (_config, SettingsService, _auth) {
const storeURL = _config.storeURL
return SettingsService.fetchStore(storeURL)
}
}
})
@eddiemonge @nateabele @christopherthielen was following this https://github.com/angular-ui/ui-router/issues/1903 Is this still relevant? Do i need to add ResolvePolicy? Checking the docs here mentions that resolves for parent states are fetched before resolves for child states.
.
Even after injecting the _auth
promise returned from the parent, the SettingsService.fetchStore
is not waiting for the _auth
to complete. Inputs would be of great help.
@GhazanfarKhan did you find a fix..
No I solved it in different way.
@GhazanfarKhan out of ui-router?
No but logics were changed because of this.
@eddiemonge @nateabele @christopherthielen sorry guys. it was my mistake. i had an api call in the run function which troubled me.. @GhazanfarKhan thanks for your help.
Glad to see that.
You were calling $state.go inside of a resolve block, which is generally a bad idea. You'll see a transition superseded warning in a developer log whenever you do that. Resolve should just be used to obtain async data, not for router flow control. The appropriate place for that flow altering behavior would be via the return value of a transition hook, defined separately.
I have a parent route called engine. Here I am validating token, loading all db stuff, checking boolean values and navigating to different routes based on data. This whole process works fine if I navigate from parent to child but when I refresh child route its controller init function trigger first before parent resolve got finished.
Here is my sample code
I am tracking different page rendering events in database. This breaks the event login if I refresh the page in survey route then survey rendered status got executed first. How do I handle this scenario.