跳到正文
产品桌面工具TASTECAD图纸查看TASTEFILES文件管理TASTEFTP文件传输TASTESSH远程工作空间TASTEZIP压缩与解压TASTEWINM文件管理开发工具TASTECODERust 集成开发环境TASTESTUDIO集成开发与测试环境TASTEETL数据整合(ETL)服务器TASTEREMOTE远程桌面服务器TASTEGEO空间信息服务器TASTEMAIL邮件工作空间投资TASTESTOCK股票自动交易桌面应用开始使用下载文档购买全部产品
市场
资讯
技术资讯今日开发资讯开发文档编程语言RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular服务端框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express应用与桌面框架TauriFlutterReact NativeElectron算法算法基础核心算法进阶算法实用算法
社区项目开发日志提示词AI 工具问题作品展示社区指南
合作技术传授网站构建桌面应用构建发布与支付流水线销售合作伙伴联系我们
服务远程桌面安装包定制
TASTEDEV
产品

桌面工具

TASTECAD复杂图纸,轻松打开TASTEFILES只要需要的文件,最快送达TASTEFTP让文件往来,干净利落TASTESSH你与服务器之间,连接更牢靠TASTEZIP压得更快,解得更稳TASTEWINM以键盘为主、用两个窗格整理文件的文件管理器

开发工具

TASTECODE在一个窗口中完成 Rust 应用的编辑、构建、调试和测试TASTESTUDIO从编辑到远程测试,再到经批准的 AI 修复TASTEETL边看数值,边搬数据

服务器

TASTEREMOTE在自己的服务器上运行的远程桌面TASTEGEO用 Rust 重新构建兼容 GeoServer 的空间信息服务器TASTEMAIL把邮件的主导权拿回自己手中

投资

TASTESTOCK何时、做什么——按你定下的规则运行的股票自动交易

开始使用

下载所有产品的最新版本文档各产品使用方法购买订阅与永久许可全部产品一览全部产品
全部产品
市场资讯
技术

资讯

今日开发资讯语言、框架、GitHub 与 AI 官方发布开发文档语言、框架与算法指南

编程语言

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

框架

Web 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular
服务端框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express
应用与桌面框架TauriFlutterReact NativeElectron

算法

算法基础复杂度分析 · 排序 · 查找 · 基础数据结构 · 树与堆核心算法图遍历 · 最短路径与最小生成树 · 动态规划 · 贪心算法 · 分治法 · 回溯法进阶算法字符串算法 · 数学与数论 · 位运算 · 线段树 · 并查集实用算法编程面试解题策略 · LRU 缓存 · 限流 · 一致性哈希
查看全部开发文档
社区
项目发现开发者与作品开发日志决策与试错提示词可复用的指令AI 工具问题Claude、Codex、Gemini 的问题与变通办法作品展示已完成的成果社区指南我们如何公开构建
合作
技术传授用 Rust 和 egui 打造原生应用网站构建10 种语言、账户、文档与下载桌面应用构建Rust 和 egui,不用 WebView发布与支付流水线签名、MSI、deb、rpm、AppImage、哈希销售合作伙伴推荐即得 30%联系我们开发、合作与投资咨询
服务
远程桌面用浏览器连接你的电脑安装包定制只装需要的,设置预先放好
购买
ZH
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
登录
登录
TASTEDEV

从小工具到更好的开发。

support@tastedev.net支持 TASTEDEV
产品产品线购买文档下载市场客户支持
社区项目开发日志提示词AI 工具问题作品展示
政策关于我们隐私政策服务条款订阅条款退款政策社区规范
账户登录注册
访客
今天
昨天
累计浏览
公司名称
GXSOFT
法定代表人
CHOI YOUNG GU
营业执照号
853-44-00368
地址
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
电话
+82-10-4404-1523
电子邮件
whitecalvin@tastedev.net
个人信息保护负责人
CHOI YOUNG GU

© 2026 TASTEDEV产品信息以已验证的开发源码为准。已发布·持续改进

Next.js 文档
Next.js
Getting Started with Next.jsProject StructureCore ConceptsData and StateTestingDeployment
讨论

Next.js 指南 · 3/6

Core Concepts

本章目前仅提供英文版。

A handful of ideas carry most of the App Router: nested layouts, Server and Client Components, Server Actions, rendering modes and metadata.

Layouts and pages

A layout receives its child route as children and wraps it. Any folder can have a layout, and layouts nest: the outer one wraps the inner one. Navigating between pages under the same layout keeps the layout and its state, so it is the place for navigation bars and sidebars.

// app/dashboard/layout.tsx
import Link from "next/link";

export default function DashboardLayout({ children }: { children: React.ReactNode }) {
  return (
    <section>
      <nav>
        <Link href="/dashboard">Overview</Link>
        <Link href="/dashboard/settings">Settings</Link>
      </nav>
      <div>{children}</div>
    </section>
  );
}

Server Components and Client Components

In the App Router, layouts and pages are Server Components by default. They run on the server and send only their result to the browser, so their code and imports never reach the client bundle, and they can query a database or use an API key safely.

When you need hooks such as useState or useEffect, event handlers such as onClick, or browser APIs such as window and localStorage, use a Client Component. Adding the "use client" directive at the top of a file puts that file, and the modules it imports, into the browser bundle.

// app/ui/like-button.tsx
"use client";

import { useState } from "react";

export function LikeButton({ initial }: { initial: number }) {
  const [likes, setLikes] = useState(initial);
  return <button onClick={() => setLikes(likes + 1)}>Likes {likes}</button>;
}

Server Components can import and render Client Components. Props passed across that boundary must be serializable (strings, numbers, plain objects, arrays and so on); functions cannot be passed, with Server Actions as the exception.

// app/posts/[id]/page.tsx (a Server Component)
import { LikeButton } from "@/app/ui/like-button";
import { getPost } from "@/lib/posts";

export default async function PostPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const post = await getPost(id);
  return (
    <article>
      <h1>{post.title}</h1>
      <p>{post.body}</p>
      <LikeButton initial={post.likes} />
    </article>
  );
}

The recommended pattern is to push the "use client" boundary as far toward the leaves of the tree as possible. Keep only the interactive pieces, such as a button or a form, on the client, and you ship less JavaScript. To render server-generated content inside a Client Component, pass it in as children.

对本章有疑问?
上一章Project Structure下一章Data and State

Server Actions

A Server Action (more generally, a Server Function) is an async function marked with "use server". It is called from the browser but runs on the server, handling forms and mutations without a separate API route. Passed to a form's action prop, it works even before JavaScript loads.

// app/guestbook/page.tsx
import { revalidatePath } from "next/cache";
import { db } from "@/lib/db";

export default function GuestbookPage() {
  async function addEntry(formData: FormData) {
    "use server";
    const message = String(formData.get("message") ?? "");
    await db.entry.create({ data: { message } });
    revalidatePath("/guestbook");
  }

  return (
    <form action={addEntry}>
      <input name="message" required />
      <button type="submit">Sign</button>
    </form>
  );
}

Treat every Server Action as a public endpoint: check auth and validate input inside it.

Rendering: static, dynamic and streaming

Next.js decides, route by route, when HTML is produced.

ModeWhen HTML is producedGood fit
Static renderingAhead of time, at build or revalidationMarketing pages, blog posts, docs
Dynamic renderingOn every requestPersonalized dashboards, search results
StreamingIn chunks, as parts become readyPages that mix fast and slow data

Reading request-time information such as cookies(), headers() or search params, or reading uncached data, makes that part render at request time. Wrap slow parts in <Suspense>, or add a loading.tsx next to the page, and Next.js sends the rest of the page first and streams the remaining content as it resolves.

// app/dashboard/page.tsx
import { Suspense } from "react";
import { RecentOrders } from "./recent-orders";

export default function DashboardPage() {
  return (
    <main>
      <h1>Dashboard</h1>
      <Suspense fallback={<p>Loading orders...</p>}>
        <RecentOrders />
      </Suspense>
    </main>
  );
}

Recent releases also offer Cache Components (the cacheComponents option), which mixes a static shell with dynamic parts on one page. This area is evolving, so check the docs for your version.

Metadata

Export a metadata object from a layout or page to set the title, description and Open Graph tags, or a generateMetadata function when they depend on data. Both are supported only in Server Components.

// app/blog/[slug]/page.tsx
import type { Metadata } from "next";
import { getPost } from "@/lib/posts";

export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
  const { slug } = await params;
  const post = await getPost(slug);
  return { title: post.title, description: post.summary };
}

Summary

  • Layouts nest and persist across navigation; pages provide the content for each URL.
  • Components are Server Components by default; split out only the interactive parts with "use client".
  • Server Actions handle forms and mutations on the server, but they still need auth checks and input validation.
  • Routes render statically or dynamically, and Suspense or loading.tsx enables streaming.
  • Use metadata and generateMetadata to give every page proper search information.

0 条评论

热门评论最新优先

登录 · 登录后即可发表评论。