Choose a CMS for Next.js: App Router and Contentful Example
- Authors

- Name
- Geeks Kai
- @KaiGeeks

A CMS supplies an editing workflow and content API; Next.js renders the website. Choose the editing and operating model before comparing brand names. Server rendering can expose content to crawlers, but it does not guarantee indexing or a ranking increase.
This example targets Next.js 16 App Router, with Cache Components disabled, and Contentful's Content Delivery API. It reads published content on the server with an explicit no-store policy. It is not a Pages Router example, a preview system, or a benchmark of CMS vendors.
| Model | Suitable starting point | Costs and responsibilities to check |
|---|---|---|
| Repository Markdown or MDX | Developers edit a small documentation site or blog | Git review, build time, media handling, and a writing interface if non-developers need one |
| Hosted headless CMS | Editors need a separate interface and managed content API | Seats, environments, API limits, localization, asset storage, export, and preview requirements |
| Self-hosted CMS | The team needs control over its content infrastructure | Database, backups, upgrades, authentication, security updates, hosting, and the product's actual license |
These are decision criteria, not a popularity ranking. A hosted service and its open-source starter are different products. Check each vendor's current plan and license against your requirements; no price comparison or universal winner is claimed here.
In a Contentful space, choose an environment and enable the en-US locale used by this example. Create a content type whose API ID is post, with required fields title (short text), slug (short text), and body (long text, plain text). Make slugs unique through editorial validation. Rich Text produces a structured document and needs a renderer; it is not interchangeable with the plain-text body below.
Create an entry with title "Hello from the CMS", slug "hello", and body "This content is published." Publish the content type and entry. Create a Content Delivery token with access to that environment. In the Next.js project's server environment, configure CONTENTFUL_SPACE_ID, CONTENTFUL_ENVIRONMENT_ID, and CONTENTFUL_DELIVERY_TOKEN. Use the chosen environment's ID, not its display label. Do not prefix these variables with NEXT_PUBLIC or place a management token in the browser. The endpoint below is for Contentful's standard delivery region; EU data residency uses the documented regional endpoint.
Create lib/contentful.mjs. Keep the server-only guard: it prevents accidental use from a Client Component. A missing entry returns null; configuration, HTTP, and malformed-content errors remain visible failures rather than empty posts.
import "server-only"
function validatePost(collection) {
if (!Array.isArray(collection.items) || !Number.isInteger(collection.total)) {
throw new Error("Invalid Contentful collection")
}
if (collection.total === 0 && collection.items.length === 0) {
return null
}
if (collection.total !== 1 || collection.items.length !== 1) {
throw new Error("Expected exactly one published post per slug")
}
const fields = collection.items[0]?.fields
if (!fields || [fields.title, fields.slug, fields.body].some(value => typeof value !== "string")) {
throw new Error("Post requires title, slug, and plain-text body fields")
}
return { title: fields.title, slug: fields.slug, body: fields.body }
}
export async function loadPublishedPost({ slug }) {
if (typeof slug !== "string" || slug.trim() === "") {
throw new TypeError("slug must be a non-empty string")
}
const spaceId = process.env.CONTENTFUL_SPACE_ID
const environmentId = process.env.CONTENTFUL_ENVIRONMENT_ID
const deliveryToken = process.env.CONTENTFUL_DELIVERY_TOKEN
if (!spaceId || !environmentId || !deliveryToken) {
throw new Error("Configure the server-side Contentful environment variables")
}
const endpoint = new URL("https://cdn.contentful.com/spaces/" + encodeURIComponent(spaceId) + "/environments/" + encodeURIComponent(environmentId) + "/entries")
endpoint.search = new URLSearchParams({ content_type: "post", "fields.slug": slug, locale: "en-US", limit: "2" }).toString()
const response = await fetch(endpoint, {
headers: { Authorization: "Bearer " + deliveryToken },
cache: "no-store",
})
if (!response.ok) {
throw new Error("Contentful delivery request failed: HTTP " + response.status)
}
const collection = await response.json()
return validatePost(collection)
}
Create app/blog/[slug]/page.jsx. This example assumes the usual @/ alias maps to the project source root. The App Router awaits params and calls the server module directly; it does not repeat the request in a client-side Effect. React renders these strings as text. Do not add dangerouslySetInnerHTML to render untrusted CMS markup.
import { notFound } from "next/navigation"
import { loadPublishedPost } from "@/lib/contentful.mjs"
export default async function PostPage({ params }) {
const { slug } = await params
const post = await loadPublishedPost({ slug })
if (!post) {
notFound()
}
return (
<article>
<h1>{post.title}</h1>
<p>{post.body}</p>
</article>
)
}
A Contentful account, configured space, and published entry are required for this live loop. Offline response fixtures can verify the request and validation logic, but they do not establish account access, publication propagation, or production integration.
getStaticProps remains a Pages Router API for files under pages. It does not belong in an App Router Server Component. Do not copy the earlier Pages Router example into app/blog/[slug]/page.jsx.
The example deliberately specifies no-store rather than relying on a version-dependent default. In Next.js 16 projects that enable Cache Components, use that mode's documented caching model instead of assuming this configuration applies unchanged. For a larger site, design a cache lifetime and authenticated publication webhook or another revalidation strategy. Draft previews need separate access control and preview-token handling. Metadata, asset optimization, pagination, locale routing, and production error views are separate integration work.