data.map is not a function at sitemap
Unanswered
Thrianta posted this in #help-forum
ThriantaOP
can anyone please help me 🙠I am trying to crate an dynamic site map for my nextjs14. here the error I am getting
⨯ TypeError: data.map is not a function
at sitemap (webpack-internal:///(app-metadata-route)/./app/sitemap.js:14:23 my code import domain from './components/domain'
import axios from 'axios';
export default async function sitemap() {
const SiteMapUrl = `${domain}`;
// Get All Posts from CMS
const baseUrl = `${domain}/sitemap/`;
const data = await axios.get(baseUrl);
const Blog = data.map((data)=>({
url: 'https://acme.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
}))
return [
{
url: 'https://acme.com',
lastModified: new Date(),
changeFrequency: 'yearly',
priority: 1,
},
{
url: 'https://acme.com/about',
lastModified: new Date(),
changeFrequency: 'monthly',
priority: 0.8,
},
{
url: 'https://acme.com/blog',
lastModified: new Date(),
changeFrequency: 'weekly',
priority: 0.5,
},
...Blog
]
}2 Replies
const { data } = await axios.get(baseUrl);also kinda unrelated, but you should look into using normal fetch too: https://www.adios-axios.com/