Next.js App Router

Last updated: 2026-11-02

Next.js App Router App Router

The App Router is the file-convention router introduced in Next.js 13+: every folder under app/ becomes one URL segment, page.tsx defines the page, layout.tsx is the shared layout that is not re-rendered on navigation, and the loading and error files take care of loading and error states automatically. The result is routing with almost no boilerplate.

GroupEcosystem
KindPattern
SinceIntroduced with Next.js 13 (App Router), still evolving in 14 / 15

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

app/
├─ layout.tsx        # root layout: shared by every route
├─ page.tsx          # route / (home page)
├─ about/
│  └─ page.tsx       # route /about
└─ posts/
   ├─ page.tsx       # route /posts
   └─ [slug]/
      └─ page.tsx    # dynamic route /posts/:slug

// app/about/page.tsx — a server component can be async by default
export default async function AboutPage() {
  return <h1>About us</h1>
}

⚙️ Parameters

page.tsxThe only entry file for a route; without it in a folder no route is generated.
layout.tsxThe shared layout component: it stays mounted while child routes change and is not re-rendered, which makes it the right place for a nav bar or a sidebar.
[slug] dynamic segmentA folder name in square brackets declares a dynamic parameter, and the page component reads the actual value from params.slug.

Returns:No return value — the App Router is a file-convention router; the rules are described in the syntax and the example.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

Simulation: the left panel is a page switcher — clicking one of the four route buttons highlights it in blue and changes the current page; the file-tree panel on the right shows the app/ file path that backs the current URL in real time, for example /posts/hello maps to app/posts/[slug]/page.tsx. It makes the files-are-routes convention visible at a glance.

💡 Key Points

💡 Tip A layout stays mounted while routes change, so putting the nav bar and the sidebar there avoids re-rendering the whole page and keeps their internal state.
ℹ️ Info A page.tsx without 'use client' at the top is a server component, so you can await data directly and no useEffect is needed.
⚠️ Warning Folder names decide the URL and are case sensitive: renaming a folder changes the route, so remember to update the internal links.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q What is the difference between the App Router and the Pages Router?
A The Pages Router uses a pages/ folder plus data functions such as getServerSideProps; the App Router uses the app/ folder convention, defaults to server components and nests layouts more naturally — it is the official recommendation for new projects.
Q What is the difference between layout and template?
A A layout stays mounted and is not re-rendered when child routes change; a template is mounted again on every navigation (which replays its enter animation), so use a template only when you want fresh state on every visit.
Q How do I define a dynamic route?
A Use square brackets in the folder name: app/posts/[slug]/page.tsx maps to /posts/:slug, and the page component receives the slug in its params argument; [...slug] even captures several path segments.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏