0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

速習App Router#4 ネストされたlayout.tsx

Last updated at Posted at 2024-02-27

はじめに

この記事は下記の講座で学んだ内容をまとめています。
理解が怪しい所があるので教えてくれるととても嬉しいです。

目次

1.速習App Router#1
2.速習App Router#2
3.速習App Router#3
4.速習App Router#4 <- この記事
5.速習App Router#5
6.速習App Router#6
7.速習App Router#7

ネストされたlayout.tsxの挙動を理解する

このようなlayout.tsxがネストされているファイル構造を想定します。

app/nested-layout
├── page.tsx
    layout.tsx
    second
     └─ page.tsx
        layout.tsx
        third
         └─ page.tsx
             layout.tsx
             fourth
              └─ page.tsx

・http://localhost:3000/nested-layout -> app/layout.tsx +
app/nested-layout/layout.tsx + app/nested-layout/page.tsx が描画

・http://localhost:3000/nested-layout/second -> app/layout.tsx +
app/nested-layout/layout.tsx + app/nested-layout/second/layout.tsx +
app/nested-layout/second/page.tsx が描画

・http://localhost:3000/nested-layout/second/third -> app/layout.tsx +
app/nested-layout/layout.tsx + app/nested-layout/second/layout.tsx +
app/nested-layout/second/third/layout.tsx + app/nested-layout/second/third/page.tsx が描画

・http://localhost:3000/nested-layout/second/third/fourth -> app/layout.tsx +
app/nested-layout/layout.tsx + app/nested-layout/second/layout.tsx +
app/nested-layout/second/third/layout.tsx +
app/nested-layout/second/third/fourth/page.tsxが描画

ここから アクセスされたURLに対応するフォルダ内のpage.tsxapp/layout.tsxまで
上にlayout.tsxでラップしながら描画内容が作成されるという事が分かる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?