Skip to main content

Render BILDIT Pages as Next.js URLs

A page in the Visual Experience Engine (VXE) is a slug plus an optional linked asset (HTML). This guide fetches those published pages and serves each slug as a URL on a Next.js App Router site — /about-us for a page whose slug is about-us.

Scheduled content is a separate setup. Slots on these URLs still come from the @bildit-platform/nextjs SDK. Finish that guide first so BilditProvider, middleware, and BILDIT_API_KEY / BILDIT_API_URL are already in place.

The SDK connector does not fetch pages

RemoteConnector in @bildit-platform/nextjs-api loads scheduled content (getWebBanners). Page routes call /remote-pages and /remote-page with fetch, using the same API key and VXE base URL.

Before you start​

  • The Integration Guide is done: env vars, middleware that sets x-pathname, and BilditProvider in the root layout.
  • At least one published page in the VXE, with a unique slug. See How to create a page.
  • If the page should show HTML, link a published asset. A page with no published asset still becomes a URL; the body is empty.
  • The page is omitted from the API when it is unpublished, archived, or deleted. The same rules apply to a linked asset that is scheduled outside its window. See Pages.

How a slug becomes a URL​

VXE slugRequestSite URL
about-usGET /remote-page?slug=about-us/about-us
help/faqGET /remote-page?slug=help/faq/help/faq

The public path is /${slug} with no extra prefix. Scheduled content on that URL matches Location against that path (/about-us), because middleware already forwards x-pathname and the root layout loads banners for the current path.

A concrete route such as app/shop/page.tsx keeps priority over the catch-all below. Use the catch-all for VXE pages, and keep routes you own as their own files.

Step 1 — Fetch pages​

Create lib/bildit-pages.ts. Both helpers run on the server. They reuse BILDIT_API_URL (the VXE instance root — the host you log into BILDIT at) and BILDIT_API_KEY.

export interface BilditPageSummary {
id: string
name: string
slug: string
contentId?: string
createdAt?: number
updatedAt?: number
}

export interface BilditPageContent {
id: string
name: string
slug: string
code?: string
status?: string
url?: string
}

export interface BilditPage extends BilditPageSummary {
content?: BilditPageContent
}

function pagesUrl(path: string, params: Record<string, string> = {}) {
const base = process.env.BILDIT_API_URL
const key = process.env.BILDIT_API_KEY
if (!base || !key) return null

const url = new URL(path, base.endsWith('/') ? base : `${base}/`)
url.searchParams.set('key', key)
for (const [name, value] of Object.entries(params)) {
url.searchParams.set(name, value)
}
return url
}

/** Published pages, in menu order (creation date). */
export async function getPublishedPages(): Promise<BilditPageSummary[]> {
const url = pagesUrl('/remote-pages')
if (!url) return []

try {
const response = await fetch(url, { cache: 'no-store' })
if (!response.ok) return []
const body = (await response.json()) as { data?: BilditPageSummary[] }
return Array.isArray(body.data) ? body.data : []
} catch (error) {
console.error('[BILDIT] Failed to load pages:', error)
return []
}
}

/** One published page, including its linked asset when that asset is published. */
export async function getPublishedPage(slug: string): Promise<BilditPage | null> {
const url = pagesUrl('/remote-page', { slug })
if (!url) return null

try {
const response = await fetch(url, { cache: 'no-store' })
if (!response.ok) return null
const page = (await response.json()) as BilditPage
if (!page?.slug) return null
return page
} catch (error) {
console.error(`[BILDIT] Failed to load page "${slug}":`, error)
return null
}
}

GET /remote-pages returns { data: [...] }. GET /remote-page?slug= returns the page object itself. When the page has a published asset, that asset is content (content.code is the HTML). GET /remote-pages?slug= is the same single-page lookup.

cache: 'no-store' reads the VXE on each request, so a publish or unpublish shows up without a rebuild. To cache responses, switch both calls to next: { revalidate: 60 } and drop force-dynamic on the route in Step 2.

BILDIT_API_URL is only the origin (https://your-site.web.app, or https://admin.bildit.co on the shared instance). The helpers append /remote-pages and /remote-page.

Step 2 — Serve each slug as a route​

Create app/[...slug]/page.tsx. The catch-all matches /about-us and nested slugs such as /help/faq. It does not match /, so your existing home page stays in place.

import { notFound } from 'next/navigation'
import type { Metadata } from 'next'
import { SlotPlaceholder } from '@bildit-platform/nextjs'
import { getPublishedPage } from '@/lib/bildit-pages'

export const dynamic = 'force-dynamic'

interface CmsPageProps {
params: Promise<{ slug: string[] }>
}

async function loadPage(params: CmsPageProps['params']) {
const { slug } = await params
return getPublishedPage(slug.join('/'))
}

export async function generateMetadata({ params }: CmsPageProps): Promise<Metadata> {
const page = await loadPage(params)
return { title: page?.name }
}

export default async function CmsPage({ params }: CmsPageProps) {
const page = await loadPage(params)
if (!page) notFound()

const html = page.content?.code

return (
<main>
<h1>{page.name}</h1>
{/* Location for banners is the public path, e.g. /about-us.
The root layout already fetched them for x-pathname. */}
<SlotPlaceholder slotId="slot1" />
{html ? <article dangerouslySetInnerHTML={{ __html: html }} /> : null}
</main>
)
}

On Next.js 14, params is a plain object. Use { params }: { params: { slug: string[] } } and read params.slug directly.

content.code is the HTML body of the linked asset from your VXE. An external asset has a url and no HTML body — send visitors to content.url (or link it) when code is absent. See External assets.

slotId must match the web slot on the scheduled content, and that item's Location must be the public path (/about-us). The root layout from the integration guide already loads banners for x-pathname, so this route only places the slot.

The list endpoint is the menu, in creation order. Drop this server component where site navigation renders, for example inside the root layout's children wrapper.

import Link from 'next/link'
import { getPublishedPages } from '@/lib/bildit-pages'

export default async function PageNav() {
const pages = await getPublishedPages()
if (pages.length === 0) return null

return (
<nav aria-label="Pages">
<ul>
{pages.map((page) => (
<li key={page.id}>
<Link href={`/${page.slug.replace(/^\/+/, '')}`}>{page.name}</Link>
</li>
))}
</ul>
</nav>
)
}

Verify​

  1. Publish a page with slug about-us and a published asset.
  2. Open /about-us. The page title and asset HTML render.
  3. Unpublish the page and reload. The route returns the not-found page.
  4. To show scheduled content on that URL, set the item's Location to /about-us and place a matching <SlotPlaceholder>.

Troubleshooting​

  1. 404 for a page you just published. The page must be published, and not archived or deleted. The query slug has no leading slash (about-us); the browser path does (/about-us).
  2. URL loads, body is empty. The page has no linked asset, or the asset is unpublished or outside its schedule. content is present only when that asset is returned.
  3. Slots on the VXE page are empty. Location must equal the public path. A free trial still leaves scheduled content blank on the live site — see Free-trial plan entitlement. Page HTML from /remote-page is independent of that check.
  4. A new page stays missing. cache: 'no-store' (Step 1) reads through. If you switched to revalidate, wait for that window or redeploy.
  5. The catch-all swallowed an existing route. Move that URL to its own app/.../page.tsx. Specific routes win over [...slug].
  6. Every page request fails. BILDIT_API_URL must be the VXE host that holds this website's data, with no path. The same value the integration guide uses for banners.