为什么我的动态 sitemap.xml 不起作用?

问题描述 投票:0回答:1

我正在使用nextjs14。根据 nextjs 文档,我在应用程序目录中创建了一个 sitemap.js 文件来创建动态站点地图,但是当我访问 http://localhost:3000/sitemap.xml 时,我看到 404 not find

这是我的代码

 app
   sitemap.js


export default function sitemap() {
  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,
    },
  ]
}

但是当我在应用程序目录中创建 sitemap.xml 时,我只能看到静态内容,而无法从 sitemap.js 获取任何内容

javascript reactjs next.js sitemap
1个回答
0
投票

最后我发现我的代码没有问题。对于 localhost,站点地图的正确 URL 路径为 http://localhost:3000/sitemap.xml/0.1。但是,在生产环境中,它将是 http://domainname/sitemap.xml。

© www.soinside.com 2019 - 2024. All rights reserved.