Skip to main content
Next.js projects use separate server and client Fimo surfaces. The application keeps its file-system routes, rendering policy, locale infrastructure, links, document metadata, and SEO. Install fimo-next and fimo-react alongside fimo at the same version:

Configure the runtime

Next.js owns its route output and 404 behavior, so it needs no catch-all rewrite.

Connect the application

Render FimoProvider once at the application root. It resolves the connection to your Fimo project on the server, hands only the public connection (tenant content URL, Branch, optional preview script) to the browser, and supplies React Query, labels, and the Studio preview script to everything below it. You do not create, copy, or read Fimo runtime environment variables.
  • Locally, the connection comes from the linked project (.fimo/project.json) and the active git branch, so git checkout switches Branches.
  • Hosted previews and production builds receive it from the platform.
  • To point the app at another host, set FIMO_CONTENT_API_URL (and optionally FIMO_ENV); an explicit value always wins over derivation.
withFimo in next.config only adds the hosted preview origins to next dev; it is not the application’s connection.

Generate content clients

Create src/schemas/<Uid>.json and run fimo schemas push <Uid>. Fimo generates:
  • <Uid>.ts for server reads and serialization;
  • <Uid>.client.ts for React Query hooks and hydration;
  • <Uid>.types.ts as an internal shared type module;
  • index.ts as the generated content registry.
Server Components and data functions use fimo-next plus generated server modules. Client Components use fimo-next/client plus generated .client.ts modules. Do not import client modules into server-only code.

App Router

Wrap the root layout with FimoProvider from fimo-next. It is a Server Component, so no page, route, or component receives a runtime prop:
Server Components can read and render tracked values directly:
Client Components use generated .client hooks and useLabels from fimo-next/client under that provider. fimo-next requires @tanstack/react-query as a peer dependency. FimoProvider also owns the optional Studio preview runtime. Application code does not add a preview bridge, read Fimo preview environment variables, or inject a preview script.

Pages Router

Wrap the root in pages/_app.tsx with FimoProvider from fimo-next/client. Pages Router has no Server Component above _app, so this provider resolves the connection while the server renders _app and writes it into the document for the browser:
getStaticProps and getServerSideProps must return plain JSON. Serialize tracked content before returning props, then hydrate it with the generated client module:
Use the same pair with getServerSideProps. Static slug routes list slugs in getStaticPaths and load entries with getBySlug().

Labels and locales

Pass the locale already resolved by the Next.js application into Fimo reads and providers.