Motivation
As for the date of writing this post it is impossible to dynamically generate sitemap.xml in NuxtJS for dynamic routes using ...
For further actions, you may consider blocking this person and/or reporting abuse
Great article, thanks. Question, is there way to set the hostname in nuxt.config.js dynamically running with server.js? Example, this would be helpful in case of multiple domains my-host.com and my-host-b.com are pointing to the same nuxt app.
Hi!
Not quite sure what do you mean, but you can access nuxt config inside your module by
this.nuxt.options.sitemap.hostname
. Also you can use differentenv
s.Hey men, thanks for replying.
Well, the host needs to be dynamic, where I've different data connected to each host.
Example domains:
tourzomer.com
fantaciclo.it
grandtourfantasy.com
All domains are for different purposes and have dynamics path for teams and others. So, in the nuxt config or sitemap config I call call for example teams per domain from my backend. But, in order to do i need to know which domain it is. So, i set a client-host to my call, but for some reason i do not know which domain the app is.
Does this make sense?
Still don't get it:)
But maybe you can add a custom header to your API calls. And each of your websites will have a custom header, for e.g.
x-platform: tourzomer
,x-platform: fantaciclo
and so on.Hi, yeah that's the solution, but the problem is that I can't access the hostname tourzomer or fantaciclo in nuxt config or the utils helper I have to get the routes.
Have you found a solution? I'm in the same situatien and going crazy here..
I wondered why the generate was able to display everything I needed for my sitemap and the sitemap module couldn't. Seems counterintuitive.
That's a great tutorial.
Could you add the bit of typescript but in JS ? I'm too poorly skilled to unpack your TS and try to put it in my project. I also tried to add TS to my nuxt project but it throws an error and I'm not too kin to add 3 packages just for this.
Regarding your question about sitemap module not generating dynamic routes: github.com/nuxt-community/sitemap-... i think that maintainers of the module filter out the dynamic routes.
And here is none-typescript version of the project - github.com/andynoir/artcile-nuxt-d...
Thank you so much
Hi Andrey
Great Post. Loved it.
I was wondering what could be setup for SSR type webapp.
For example,
I usually deploy nuxt SSR webapp using npm run build in production and I would be very helpful If can use above method.
I tried looking for hook with build:done something but couldnot get any in Link.
nuxtlink
Also Since you have generate all dynamic 10 pages of users but for realtime siite,
We will have dynamic new content that are being generated after generate nuxt command so what can be the best solution?
❤️ from Nepal
Sorry for the late reply, but I think there is no best solution in this case.
In my case I am using SSG and I don't have such problem because my routes and sitemap files are FIXED in some way or another, if someone want to add a new page or other content the entire app has to be rebuild hence the sitemap will be rebuilt too.
In your case the content is always dynamic, but the sitemap will be generated only after deploy if I understand correctly. I think it is better to address this problem to the maintainer of the library, because I remember that he was going to add such feature.
Hey Sushil! Have you found a solution for this problem? I have to solve the same issue and would like to understand how to serve the sitemap in production when new content is added to the website.
cheers!
This article is very useful, thank you very much! ✌️
I believe that the best way to exclude the routes is not to use the env variable, but read the routes to exclude in the configuration of the sitemap module from
this.nuxt.options.sitemap.exclude
Or simply avoid the whole module and TS thing by adding this to nuxt.config.js
hooks: {
generate: {
async done(context) {
const allRoutes = await Array.from(context.generatedRoutes);
context.options.sitemap.routes = await [...allRoutes];
},
},
},
Ehi Andrey, great point here. Thanks
Do you know if it's possible to get head meta tags after nuxt generate is done?
I want to exclude some routes from sitemap it a certain meta tag is properly generated.
Sorry for the late reply, I'm not quite sure what do you mean. Do you want to prevent some routes to be included into sitemap if your meta tag meets some criteria ? If yes, unfortunately I don't have an answer for you, it would be just a brute force console logging for me to answer your question. Take a look here, it might help you.
This helped me a lot, thanks!
can use that for website has pagination? tks
Can't quite understand what do you mean. Sitemap is not related to pagination by any means.
Hi there,
I am having issues because i can see the dynamic routes being generated but it doesn't add them to the sitemap.xml. I am having the exact same setup as you have. Any ideas?
I'm trying to implement this but having a problem. When I run my Nuxt project in dev ($ npm run dev), I get:
Error: Cannot find module '@/modules/generator'
Do have any suggestions?
Hi!
Which version of Nuxt are you using ? A quote from the docs:
Also check out for typos and file extensions.
Awesome Tutorial 👍👍👍👍👍👍
Thanks it works !