@genga-cms/react-router
Genga for React Router in framework mode. One resource
route serves the Genga paths (the admin app, its API, the media, MCP), and loadPage reads the
document of a page in its loader.
| Package | React Router | Node |
|---|---|---|
@genga-cms/react-router |
^7.18.4 or ^8.5.2 |
>=22.12 |
The version of @genga-cms/react-router is the version of genga.
Set up
route('/admin/*', 'routes/genga.ts', { id: 'genga-admin' }),route('/media/*', 'routes/genga.ts', { id: 'genga-media' }),
// app/routes/genga.tsimport { gengaResourceRoute } from '@genga-cms/react-router';import { genga } from '../.server/genga';const route = gengaResourceRoute(genga);export const loader = route.loader;export const action = route.action;
// app/routes/post.tsximport { Blocks, usePreviewData } from '@genga-cms/react';import { loadPage } from '@genga-cms/react-router';export const loader = ({ request, params }: Route.LoaderArgs) => loadPage(genga, request, 'posts', params.slug);export const headers = ({ loaderHeaders }: Route.HeadersArgs) => loaderHeaders;export default function Post({ loaderData }: Route.ComponentProps) { const { data } = usePreviewData(loaderData.doc, loaderData.preview); return <Blocks blocks={data.body} registry={blocks} preview={loaderData.preview} />;}WARNING: do not write export const { loader, action } = gengaResourceRoute(genga). React
Router cannot remove a destructured loader from the browser build, and the build fails.
gengaResourceRoute(genga, { unavailable })takes the instance, or a function that gives it. If the function gives null (the CMS is off), the route answersunavailable(request), by default a 503.loadPagereturns the document in the public shape (absolute media URLs, rich text withhtml) with itsETagandCache-Control. It throws a 301 to the new path of a renamed slug, and a 404. With?genga-preview=<id>, it gives the draft to a signed-in editor of the same origin. With a remote source (createRemoteSourceofgenga/remote), it checks the preview token.- The routes need no admin route module, no
genga/admin.cssand nodata-genga-adminin the root layout. To move an app of genga 0.3, read the migration guide.