-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Description
That's just a suggestion. Since we don't have any example of a middleware inside a template but we use an undocumented api folder which is just a discrepant addition in my opinion. Why not use middleware as Nuxt intended? api/people.ts can be placed in middleware folder and rewritten as such:
export default async function({store, error, redirect}){
if(process.client) return;
await store.dispatch('getPeople')
}
and in the store actions:
async getPeople({commit}){
commit('setPeople', await axios.get('/random-data.json').data.slice(0,3));
}
and in nuxt.config.js module.exports object
router: {
middleware: 'people'
},
this way we can showcase how middleware function can be used in the template that might be beneficial for a lot of users
Metadata
Metadata
Assignees
Labels
No labels