Next

作者 vercel-labsfc2a696a50a3無授權條款18K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫昨天更新

Next.js renderer for json-render that turns JSON specs into full Next.js applications with routes, layouts, SSR, and metadata. Use when working with @json-render/next, building Next.js apps from JSON specs, or creating AI-generated multi-page applications.

AI 產生的概覽

將 JSON 規格渲染為包含路由、版面配置、SSR 與中繼資料的完整 Next.js 應用程式。

功能
此技能說明 @json-render/next,這是一個把 NextAppSpec JSON 物件轉換成完整 Next.js 應用程式的渲染器。內容涵蓋如何定義包含中繼資料、版面配置、路由與狀態的規格,再透過 createNextApp 建立應用程式並串接路由檔案。它也說明內建元件、動作、伺服器端資料載入器、SSR 行為,以及伺服器端與用戶端進入點。
適用情境
適用於使用 @json-render/next、依 JSON 規格建置 Next.js 應用程式,或產生 AI 生成的多頁面應用程式。適合需要由規格驅動路由、版面配置、中繼資料與伺服器渲染的工作。
執行需求
需要一個 Next.js 專案,並安裝 npm 套件 @json-render/core、@json-render/react 與 @json-render/next。此技能不含指令碼,僅為說明文件。伺服器端資料載入器可能需要存取資料庫等資料來源。

@json-render/next

Next.js renderer that converts JSON specs into full Next.js applications with routes, pages, layouts, metadata, and SSR support.

Quick Start

bash
npm install @json-render/core @json-render/react @json-render/next

1. Define Your Spec

typescript
// lib/spec.tsimport type { NextAppSpec } from "@json-render/next";
export const spec: NextAppSpec = {  metadata: {    title: { default: "My App", template: "%s | My App" },    description: "A json-render Next.js application",  },  layouts: {    main: {      root: "shell",      elements: {        shell: { type: "Container", props: {}, children: ["nav", "slot"] },        nav: { type: "NavBar", props: { links: [          { href: "/", label: "Home" },          { href: "/about", label: "About" },        ]}, children: [] },        slot: { type: "Slot", props: {}, children: [] },      },    },  },  routes: {    "/": {      layout: "main",      metadata: { title: "Home" },      page: {        root: "hero",        elements: {          hero: { type: "Card", props: { title: "Welcome" }, children: [] },        },      },    },    "/about": {      layout: "main",      metadata: { title: "About" },      page: {        root: "content",        elements: {          content: { type: "Card", props: { title: "About Us" }, children: [] },        },      },    },  },};

2. Create the App

typescript
// lib/app.tsimport { createNextApp } from "@json-render/next/server";import { spec } from "./spec";
export const { Page, generateMetadata, generateStaticParams } = createNextApp({  spec,  loaders: {    // Server-side data loaders (optional)    loadPost: async ({ slug }) => {      const post = await getPost(slug as string);      return { post };    },  },});

3. Wire Up Route Files

tsx
// app/[[...slug]]/page.tsxexport { Page as default, generateMetadata, generateStaticParams } from "@/lib/app";
tsx
// app/[[...slug]]/layout.tsximport { NextAppProvider } from "@json-render/next";import { registry, handlers } from "@/lib/registry";
export default function Layout({ children }: { children: React.ReactNode }) {  return (    <html lang="en">      <body>        <NextAppProvider registry={registry} handlers={handlers}>          {children}        </NextAppProvider>      </body>    </html>  );}

Key Concepts

NextAppSpec

The top-level spec defines an entire Next.js application:

  • metadata: Root-level SEO metadata (title template, description, OpenGraph)
  • layouts: Reusable layout element trees (each must include a Slot component)
  • routes: Route definitions keyed by URL pattern
  • state: Global initial state shared across all routes

Route Patterns

Routes use Next.js URL conventions:

  • "/" -- home page
  • "/about" -- static route
  • "/blog/[slug]" -- dynamic segment
  • "/docs/[...path]" -- catch-all segment
  • "/settings/[[...path]]" -- optional catch-all segment

Layouts

Layouts wrap page content. Every layout MUST include a Slot component where page content will be rendered. Layouts are defined once in spec.layouts and referenced by routes via the layout field.

Built-in Components

  • Slot: Placeholder in layouts where page content is rendered
  • Link: Client-side navigation link (wraps next/link)

Built-in Actions

  • setState: Update state value. Params: { statePath, value }
  • pushState: Append to array. Params: { statePath, value, clearStatePath? }
  • removeState: Remove from array by index. Params: { statePath, index }
  • navigate: Client-side navigation. Params: { href }

Data Loaders

Server-side async functions that run in the Server Component before rendering. Results are merged into the page's initial state.

typescript
createNextApp({  spec,  loaders: {    loadPost: async ({ slug }) => {      const post = await db.post.findUnique({ where: { slug } });      return { post };    },  },});

SSR

Pages are server-rendered automatically. The createNextApp Page component is an async Server Component that:

  1. Matches the route from the spec
  2. Runs server-side data loaders
  3. Generates metadata
  4. Passes the resolved spec to the client renderer for hydration

Entry Points

  • @json-render/next -- Client components (NextAppProvider, PageRenderer, Link)
  • @json-render/next/server -- Server utilities (createNextApp, matchRoute, schema)

API Reference

Server Exports (@json-render/next/server)

  • createNextApp(options) -- Create Page, generateMetadata, generateStaticParams
  • schema -- Custom schema for Next.js apps (for AI catalog generation)
  • matchRoute(spec, pathname) -- Match a URL to a route spec
  • resolveMetadata(spec, route) -- Resolve metadata for a route
  • slugToPath(slug) -- Convert catch-all slug array to pathname
  • collectStaticParams(spec) -- Collect static params for all routes

Client Exports (@json-render/next)

  • NextAppProvider -- Context provider for registry and handlers
  • PageRenderer -- Renders a page spec with optional layout
  • NextErrorBoundary -- Error boundary component
  • NextLoading -- Loading state component
  • NextNotFound -- Not-found component
  • Link -- Built-in navigation component (wraps next/link)

來源與署名

來源:vercel-labs/json-render位於skills/next提交fc2a696

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架