Reputation: 5980
I want to add dynamic routes to be statically generated via Nuxt.
I have a client/server-side store defined thanks to asyncData
method. I want to map this store value (an array) in my nuxt.config.js
file to make it "dynamic/static" routes map for nuxt generate
command - but how to access store in that file? is this even possible?
Upvotes: 2
Views: 5123
Reputation: 549
Posting for future reference –
One solution I found was to just hardcode the data you want into the .config file.
Practical for my situation, but not always scalable.
Upvotes: 0
Reputation: 4904
You cannot access the store from the nuxt.config.js file.
The nuxt.config.js file is just a global configuration.
However, you can set dynamic routes for the generate commmand.
If you want nuxt.js to generate routes with dynamic params, you need to set an array of dynamic routes.
From the official documentation:
nuxt.config.js
module.exports = {
generate: {
routes: [
'/users/1',
'/users/2',
'/users/3'
]
}
}
If you have dynamic parameters in your routes you have two options:
1) A Function which returns a Promise
2) A Function with a callback(err, params)
Please see the documentation for more details on this: https://nuxtjs.org/api/configuration-generate/#routes
Upvotes: 4