기록을 불러오는 중입니다...
<!-- app/records/page.tsx -->
<!-- RecordsPage -->
<RecordsPageLayout>
<h1 className="mt-16 mb-6">
여정의 발자취를 작은 기록들로 남겨봅니다. 🐾
</h1>
<Suspense fallback={<RecordsPageSkeleton />}>
<Tags />
<Records searchParams={searchParams} />
</Suspense>
</RecordsPageLayout><!-- app/records/loading.tsx -->
<!-- RecordsPageSkeleton -->
<p>기록들을 불러오는 중입니다...</p>;<!-- app/records/_layout.tsx -->
<!-- RecordsPageLayout -->
<main className="mx-auto min-h-screen max-w-[768px] px-4 lg:px-0">
{props.children}
</main>loading.tsx 로 인해 아무런 레이아웃이 적용되지 않은 단순한 문구만 달랑 보여지고Suspense 에 적용된 fallback 요소인 RecordsPageSkeleton 가 보여집니다.Suspense 를 이용한 로딩 UI를 굳이 보여 줄 필요가 없어보입니다.loading.tsx 에게 역할을 전부 위임해봅시다.<!-- app/records/page.tsx -->
<!-- RecordsPage -->
<RecordsPageLayout>
<h1 className="mt-16 mb-6">
여정의 발자취를 작은 기록들로 남겨봅니다. 🐾
</h1>
<Tags />
<Records searchParams={searchParams} />
</RecordsPageLayout>Suspense 를 제거했습니다.loading.tsx 만이 렌더링 될 텐데, 기본적인 레이아웃이 적용되길 원하니 RecordsPageLayout 로 감싸줍니다.<!-- app/records/loading.tsx -->
<!-- RecordsPageSkeleton -->
<RecordsPageLayout>기록들을 불러오는 중입니다...</RecordsPageLayout>;<!-- app/records/page.tsx -->
<!-- RecordsPage -->
<RecordsPageLayout>
<Tags />
<Records searchParams={searchParams} />
</RecordsPageLayout><!-- app/records/_layout.tsx -->
<!-- RecordsPageLayout -->
<main className="mx-auto min-h-screen max-w-[768px] px-4 lg:px-0">
<h1 className="mt-16 mb-6">
여정의 발자취를 작은 기록들로 남겨봅니다. 🐾
</h1>
{props.children}
</main>h1 요소를 레이아웃으로 옮겼습니다.layout.tsx 인데 저는 _layout.tsx 를 쓰고 있었습니다./records/[slug] 페이지의 레이아웃이 상위 페이지인 /records 의 레이아웃과 겹치는 현상을 해결하기 위해 다음과 같이 코드를 수정했습니다.app/
records/
_layout.tsx << 파일명에 _를 붙여서 기본 동작을 회피
page.tsx
[slug]/
_layout.tsx << 파일명에 _를 붙여서 기본 동작을 회피
page.tsx// records/_layout.tsx
export function RecordsPageLayout(props) {
return (
<main className="...">
{props.children}
</main>
);
}
// records/_layout.tsx
export default async function RecordsPage(params) {
return (
<RecordsPageLayout>
<h1 className="...">
여정의 발자취를 작은 기록들로 남겨봅니다. 🐾
</h1>
<Suspense fallback={<... />}>
{/* ... */}
</Suspense>
</RecordsPageLayout>
);
}// records/[slug]/_layout.tsx
export function RecordPageLayout(props) {
return (
<div className="...">
{props.children}
</div>
);
}
// records/[slug]/page.tsx
export default async function RecordPage(params) {
return (
<RecordPageLayout>
{/* ... */}
</RecordPageLayout>
);
}