ルートグループとネストされたレイアウト
ルートグループ、ネストされたレイアウト、テンプレートファイルを使い、共有UIとセクション固有のUIを持つ複雑なApp Routerプロジェクトを整理します。
「ルートグループとネストされたレイアウト」はCoddyKit上の無料Next.js 15 Fullstack (App Router + Server Actions)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはNext.js 15 Fullstack (App Router + Server Actions)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Next.js 15 Fullstack (App Router + Server Actions)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Organization Matters
As an app grows, the App Router lets you structure folders for shared UI without affecting the URL. Route groups and nested layouts are the main tools.
Nested Layouts Recap
Each folder can have a layout.tsx. Layouts nest: a section layout wraps its pages while the root layout wraps everything.
export default function DashboardLayout({ children }) {
return (<section><nav>Dashboard nav</nav>{children}</section>);
}Route Groups
Wrapping a folder name in parentheses, like (marketing), creates a route group. It organizes files but is omitted from the URL.
Multiple Root Layouts
Route groups let you have different top-level layouts — for example, one for marketing pages and another for the app — by giving each group its own layout.
app/
(marketing)/layout.tsx
(marketing)/page.tsx
(app)/layout.tsx
(app)/dashboard/page.tsxURLs Stay Clean
Because (marketing) does not appear in the path, app/(marketing)/page.tsx still serves the URL /, not /marketing.
Template vs Layout
A template.tsx is like a layout but creates a new instance on every navigation, resetting state — useful for enter animations or per-route effects.
export default function Template({ children }) {
return <div className="fade-in">{children}</div>;
}When to Use Template
Use a template when you need state or effects to re-run on each navigation; use a layout when you want shared UI and state to persist across navigations.
Organizing Without Routing
You can also use route groups purely to colocate related routes under one folder without adding a URL segment, keeping the codebase tidy.
Shared UI in Layouts
Put navigation, sidebars, and providers in the nearest layout so they persist and avoid re-rendering on navigation within that section.
Loading and Error per Section
Each segment, including grouped ones, can have its own loading.tsx and error.tsx, scoping fallback UI precisely.
Putting It Together
A typical app: a (marketing) group with a public layout, an (app) group with an authenticated layout, each nesting further section layouts.
Quick Check
What does wrapping a folder name in parentheses do?
Recap
You learned to structure apps with nested layouts for persistent shared UI, route groups (name) that organize without changing URLs and allow multiple root layouts, and templates that remount on navigation.
AI チューターと学ぶ TypeScript — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 22
- レッスン
- 88
よくある質問
「ルートグループとネストされたレイアウト」レッスンは無料ですか?
はい。「ルートグループとネストされたレイアウト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Next.js 15 Fullstack (App Router + Server Actions)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Next.js 15 Fullstack (App Router + Server Actions)コースには全4レッスンが含まれています。
「ルートグループとネストされたレイアウト」で何を学びますか?
ルートグループ、ネストされたレイアウト、テンプレートファイルを使い、共有UIとセクション固有のUIを持つ複雑なApp Routerプロジェクトを整理します。 ブラウザで直接実行するハンズオンコードでNext.js 15 Fullstack (App Router + Server Actions)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Next.js 15 Fullstack (App Router + Server Actions)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのNext.js 15 Fullstack (App Router + Server Actions)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「ルートグループとネストされたレイアウト」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このNext.js 15 Fullstack (App Router + Server Actions)レッスンでコードを書いて実行できますか?
はい。すべてのNext.js 15 Fullstack (App Router + Server Actions)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- レイアウトとページコンポーネント
- 動的ルートとパラメーター
- ローディングUIとエラーUI
- ルートグループとネストされたレイアウト