概览使用 App Router 的 Route Handlers 生成 `sitemap.xml` 与 `robots.txt`,为多语言与动态内容提供精准索引。结合 `hreflang` 与 `canonical` 保持链接权重与国际化表现。sitemap.xmlapp/sitemap.xml/route.tsexport const runtime = 'edge' export async function GET() { const posts = await fetch('https://api.example.com/posts').then(r => r.json()) const urls = posts.items.map((p: any) => `https://example.com/posts/${p.slug}`) const xml = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.map(u => `<url><loc>${u}</loc><changefreq>daily</changefreq><priority>0.8</priority></url>`).join('\n')}\n</urlset>` return new Response(xml, { headers: { 'Content-Type': 'application/xml' } }) } robots.txtapp/robots.txt/route.tsexport const runtime = 'edge' export async function GET() { const body = `User-agent: *\nAllow: /\nSitemap: https://example.com/sitemap.xml\n` return new Response(body, { headers: { 'Content-Type': 'text/plain' } }) } 页面元数据与 hreflangapp/posts/[slug]/page.tsximport type { Metadata } from 'next' export async function generateMetadata({ params }: { params: { slug: string } }): Promise<Metadata> { return { alternates: { canonical: `https://example.com/posts/${params.slug}`, languages: { 'en': `https://example.com/en/posts/${params.slug}`, 'zh': `https://example.com/zh/posts/${params.slug}`, }, }, } } 治理要点`sitemap.xml` 定期更新或按需生成;为增量内容提供适当 `changefreq/priority`。`robots.txt` 指向 sitemap,避免误禁抓取;敏感路径按需 Disallow。`hreflang` 与 `canonical` 保持跨语言链接权重与去重。验证与指标搜索抓取正常,国际化结果展示正确;Next.js:15.0+;Edge Runtime:稳定

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.966156s