惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
V
V2EX
Jina AI
Jina AI
爱范儿
爱范儿
M
MIT News - Artificial intelligence
量子位
L
LangChain Blog
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
腾讯CDC
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss

Vercel News

Vercel Open Source Program: Winter 2026 cohort How Notion Workers run untrusted code at scale with Vercel Sandbox How we run Vercel's CDN in front of Discourse From idea to secure checkout in minutes with Stripe Building Slack agents can be easy Scaling redirects to infinity on Vercel Advancing Python typing Gamma builds design-first agents with Vercel How Avalara turns pipe dreams into patent-pending with v0 Keeping community human while scaling with agents How OpenEvidence built a healthcare AI that physicians actually trust Security boundaries in agentic architectures Skills Night: 69,000+ ways agents are getting smarter Video Generation with AI Gateway We Ralph Wiggumed WebStreams to make them 10x faster How Stably ships AI testing agents in hours, not weeks How we built AEO tracking for coding agents Anyone can build agents, but it takes a platform to run them Introducing Geist Pixel The Vercel AI Accelerator is back with $6m in credits Making agent-friendly pages with content negotiation The Vercel OSS Bug Bounty program is now available Introducing the new v0 Run untrusted code with Vercel Sandbox, now generally available How Stripe built a game-changing app in a single flight with v0 How Sensay went from zero to product in six weeks AGENTS.md outperforms skills in our agent evals Agent skills explained: An FAQ Testing if "bash is all you need" AWS databases are now live on the Vercel Marketplace and v0
Next.js Layouts RFC in 5 minutes - Vercel – Vercel
Lee Robinson · 2022-09-14 · via Vercel News

2 min read

The Next.js team at Vercel released the Layouts RFC a few months ago outlining the vision for the future of routing, layouts, and data fetching in the framework. The RFC is detailed and covers both basic and advanced features.

This post will cover the most important features of the upcoming Next.js changes landing in the next major version that you should be aware of.

Link to headingCreating Routes

In the new app directory, folders are used to define routes. To create a route, add a page.js file inside a folder. For example, app/page.js:

app/page.js

export default function Page() {

return <h1>Hello, Next.js!</h1>

}

A new Page inside the app directory.

A page (with the page.js naming convention) is UI that is unique to a specific route segment. In this instance, the route segment is / (or the root segment).

Each route segment is mapped to a corresponding segment in a URL path.

Each route segment is mapped to a corresponding segment in a URL path.

You can incrementally adopt the app directory from the existing pages directory.

Link to headingCreating Layouts

You can create nestable layouts that are shared across pages by adding layout.js files.

Creating routes using pages and layouts.

Creating routes using pages and layouts.

To make your first layout, you will create a new file app/layout.js.

app/layout.js

export default function RootLayout({ children }) {

return (

<html>

<head>

<title>Next.js Layouts RFC in 5 Minutes</title>

</head>

<body>{children}</body>

</html>

);

}

Root layout inside the app directory.

app/page.js above will render as a child of app/layout.js:

<html>

<head>

<title>Next.js Layouts RFC in 5 Minutes</title>

</head>

<body>

<h1>Hello, Next.js!</h1>

</body>

</html>

The rendered HTML output from the root layout and page.

Link to headingSharing Layouts

Layouts can be shared across different pages. Every route in app/ shares the same root layout, defined at app/layout.js. For example, if we created a new route segment app/blog/page.js:

app/blog/page.js

export default function BlogPage() {

return <h1>Blog Posts</h1>

}

Blog page inside the app directory.

This page would use the same root layout. app/blog/page.js would render as a child of app/layout.js.

<html>

<head>

<title>Next.js Layouts RFC in 5 Minutes</title>

</head>

<body>

<h1>Blog Posts</h1>

</body>

</html>

The rendered HTML output from the root layout and blog page.

If we wanted a custom layout for this route segment, we would create a new layout at app/blog/layout.js. For example, maybe our blog needs a sidebar navigation layout:

app/blog/layout.js

export default function BlogLayout({ children }) {

return (

<>

<aside>

<nav>...</nav>

</aside>

{children}

</>

)

}

Layout specific to the blog route segment.

app/blog/page.js would render as a child of app/layout.js and app/blog/layout.js:

<html>

<head>

<title>Next.js Layouts RFC in 5 Minutes</title>

</head>

<body>

<aside>

<nav>...</nav>

</aside>

<h1>Blog Posts</h1>

</body>

</html>

The rendered HTML output from the root layout, blog layout, and blog page.

Similarly, if we created a nested dynamic route app/blog/[slug]/page.js for an individual blog post, it would also use the same layouts:

app/blog/[slug]/page.js

export default function IndividualBlogPost() {

return (

<main>

<h1>Routing with Next.js</h1>

<p>Lorem ipsum dolor sit amet</p>

</main>

)

}

Page for a specific blog post, using a dynamic route.

<html>

<head>

<title>Next.js Layouts RFC in 5 Minutes</title>

</head>

<body>

<aside>

<nav>...</nav>

</aside>

<main>

<h1>Routing with Next.js</h1>

<p>Lorem ipsum dolor sit amet</p>

</main>

</body>

</html>

Layout for the individual blog post page with a dynamic route.

Link to headingLoading & Error Boundaries

loading.js automatically wraps a page or nested segment in a React Suspense Boundary. Next.js will show your loading component immediately on the first load and again when navigating between sibling routes.

You can use this to create meaningful loading UI for specifics part of your UI.

The Next.js Loading UI creates a React Suspense boundary.

The Next.js Loading UI creates a React Suspense boundary.

error.js automatically wraps a page or nested segment in a React Error Boundary. Next.js will show your error component whenever an error in a subtree is caught.

The Next.js Error UI creates a React error boundary.

The Next.js Error UI creates a React error boundary.

Use this to isolate errors to specific parts of an app, show specific error information, and attempt to recover.

Link to headingRoute Groups

Route groups can be used to:

  • Organize routes without affecting the URL path

  • Opt a segment out of a layout

  • Create multiple root layouts for sections of an app with a completely different UI

You can exclude routes from layouts using route groups.

You can exclude routes from layouts using route groups.

Link to headingSummary

An example app directory using some of the above concepts would look as follows:

Read the full Layouts RFC and stay tuned for more information from the Next.js team at Vercel.