Question presented to candidate: "How do you add a sitemap and a robots.txt to an App Router project, including URLs that come from the database?"
What a strong answer should cover:
app/sitemap.tsdefault-exports a function returning an array of{ url, lastModified, changeFrequency, priority }; Next.js serves it as/sitemap.xml.app/robots.tsreturns{ rules, sitemap }and is served as/robots.txt.- Both can be async and fetch data, so the sitemap can list every product or post.
- Static files (
public/robots.txtorapp/sitemap.xml) also work when nothing is dynamic. - Large sites split the sitemap with
generateSitemaps, because one sitemap file is limited to 50,000 URLs.
Clarifying questions expected:
- "How many URLs are there?" β decides whether to split sitemaps.
- "Which paths must stay out of search?" β they go in robots disallow rules and noindex metadata.
Code / implementation expected: Yes β both files, with URLs from data.