validate after fetch
[issue link]Looking at Nuxt’s request/navigation schema (and after some debugging) I discovered that a Page component’s asyncData and fetch methods are called after the validate method.
Would it be possible to flip this order so that validate is called after asyncData and fetch?
Here is my use case:
- All of my app’s data is stored in the Vuex
store - When navigating to
posts/_id, I use the route paramidto fetch some data from an API - I do so using the
posts/_id.vuepage component’sfetchmethod, passing along the route paramid—something like:store.dispatch('fetchPost', route.params.id) - An
async fetchPostaction in the Vuex store calls my API with the payloadid, returns a post record and then that record is committed to thestoreinto apostscollection/array - Assuming that the call to the API was successful and a post exists for the provided
id, I will now have my post record in my Vuexstore.state.postscollection - I would then like to be able to
validatemy dynamic Post page by finding my post record in the store’spostscollection (again using theroute.params.id) - However since
validateis called beforefetch, my store’spostscollection will be empty so that lookup returns no record and the validation fails
The only way around this is to use the nuxtServerInit action which does get called before a page’s validate method. However, this then means that this action will get quite cumbersome as I move or duplicate my route specific async calls to my API to within this action.
If validate were called after fetch then this wouldn’t be necessary and the nuxtServerInit action could remain relatively pure and simple.
Perhaps there is a reason why validate is called before that I am not aware of—either way, I would appreciate any help/suggestions.
BTW Nuxt is literally the best thing since sliced bread. Fantastic work 🎉