I need to reach dynamic meta for list of posts in my app, so.
Is there any option to get access to store from nuxt config? I wish to save some value in store just inside generating routes promise. And second - is there will be a possibility to read this data just before the static page will be generated, inside head ()?
You can not access to the store from nuxt.config.js.
The nuxt.config.js file is just a global configuration.
If you want to use special configuration, for example changing meta tags, you should use head() in your dynamic page component.
@alexchopin OK but when i'm generating my app the meta comes from global config not from component, data to head arrives from ajax call ...
I'm not sure to understand where you want to update your meta info and where they come from.
Can you tell me more about it?
@alexchopin OK. So i have i.e. 100 posts in my db, each of them have unique title, now i need to pass this title, description etc. as a unique meta data do generated static page for this post, i'm using fetch method but this is not helping at all. That's why i was asking about nuxt config integration. I'm using promise in config for single post generation. Thx for help.
OK, actually we do the same for nuxtjs.org website for each page.
You can see how you do in this file as an example.
However, if you are using fetch, I guess you are using the store to save your post, right?
@alexchopin Yeap, this is my example
async asyncData ({route, store, error}) {
let data = {
posts: null,
relatedposts: null,
metadata: {},
singlepost: {},
singlepostId: route.params.id
}
let id = route.params.id
let res = await FeedService.getPosts({id: id})
data.singlepost = res.data
return data
},
head () {
return {
title: this.singlepost.created
}
},
And after static generation i still get the config meta setup, what is wrong?
Oh, I see it's related to this bug with the dynamic generate. It will be fixed in the next release 馃憤
@alexchopin when? :) this is very important for me, clients is waiting, and he is almost ready to kill me. Maybe you can tell me how to fix it temporary? and when the new release will be alive i will remove it
@lukasborawski the new release should come very soon, we need it to in production.
We are doing our best to release asap.
The only solution is to use nuxt v.0.10.7 (latest stable release for generate option)
@alexchopin downgrade to 10.7 doesn't help me :(
@alexchopin maybe this must be lower version? Please help me.
@lukasborawski We have talked internally with @Atinux, will release with @next tag soon (Tommorrow). Stay tuned and don't worry :)
@pi0 @Atinux is the release comes out? Thx.
I'm still working on it to make it work perfectly @lukasborawski
Coming sooon :)
:) sorry for this diarrhea, but i really need this, waiting then
@Atinux any updates? :(
@Atinux @pi0 guys any info, updates? Can you tell me something? :) Much thx.
Hi @lukasborawski sorry for the late answer, we're working hard to fix the issue with the generate feature.
I'm going to publish a hot fix now
@lukasborawski can you upgrade to alpha5 (out now) and tell me if it's good now? (Please mention me so I can receive an email to answer you faster).
@Atinux :( sory, i have this error:
[nuxt] Generating...
nuxt:build App root: /Users/... +0ms
nuxt:build Generating .nuxt/ files... +1ms
nuxt:build Generating routes... +31ms
nuxt:build Generating files... +26ms
ReferenceError: r is not defined
at eval (lodash.templateSources[2]:23:11)
at Array.forEach (native)
at eval (lodash.templateSources[2]:18:10)
at .../node_modules/nuxt/dist/nuxt.js:694:29
also when i'm starting npm run dev / nuxt nothing happens, there is no dev mode, no generating, just Ready on http://127.0.0.1:3000 - it looks like server is starting but this is it, not more
@lukasborawski Do you mind sharing the repo so I can try directly?
@Atinux sory it's confidential, private :( - client owns
how can i help you to find the bug?
@Atinux any checkups? updates? Is this solution works with you?
I'm not sure to see what's wrong, as you can see alpha5 works nice here: https://nuxt-hello-world.glitch.me/about
OK, @Atinux @alexchopin @pi0 i'm back. Updated to 1.0.0-rc3
This is my nuxt.config.js
generate: {
routes: function () {
if (process.env.GENERATE_POST) {
return ['/feed/' + process.env.GENERATE_POST]
} else {
let posts = axios.get(`${process.env.BASE_URL}/posts`, {params: {size: process.env.GENERATE_POST_SIZE || 10}}).then((res) => {
return res.data.posts.map((post) => {
return '/feed/' + post.id
})
})
let users = axios.get(`${process.env.BASE_URL}/users`, {params: {size: process.env.GENERATE_POST_SIZE || 10}}).then((res) => {
return res.data.content.map((user) => {
return '/user/' + user.id
})
})
return Promise.all([posts, users]).then(values => {
return values.join().split(',').concat(['/feed/']);
})
}
},
wait: 500
},
/*
** Headers of the page
*/
head: {
title: 'Title from config',
meta: [
{ charset: 'utf-8' },
{ hid: 'description', name: 'description', content: 'Description from config.' }
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.png' }
]
},
and this is my page pages/feed/_id.vue
export default {
async asyncData ({store, route}) {
let data = {
posts: null,
relatedposts: null,
singlepost: {},
singlepostId: route.params.id
}
let res
let id = route.params.id
res = await FeedService.getPosts({id: id})
data.singlepost = res.data
return data
},
head () {
return {
title: 'Title from page',
meta: [
{ hid: 'description', name: 'description', content: 'Description from page' },
]
}
},
Posts are generating from api call and this works fine. But i don't know what i'm doing wrong but on and on still doesn't have custom meta from single page. Please help me! :(
Hi, you mean that on generating your pages, you don't have the meta tags at all?
@Atinux I have these ones from config :(
@Atinux pls heeeeeeeeeeelp :)
@lukasborawski https://discord.gg/ApjkSj, send me a private message so I can help you
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Hi @lukasborawski sorry for the late answer, we're working hard to fix the issue with the
generatefeature.I'm going to publish a hot fix now