Next.js 12 - Layout, Head component

2025. 3. 10. 20:23·♠️ Next.js 12

Next.js

⚫ Layout pattern


[Layout.js]

import NavBar from "./NavBar";

export default function Layout({ children }) {
  return (
    <>
      <NavBar />
      <div>{children}</div>
    </>
  );
}

children은 Layout component를 사용한 곳에서 자식 컴포넌트로 들어오는 컴포넌트가 들어오게 된다.

 

[_app.js]

import Layout from "../components/Layout";
import "../styles/globals.css";

export default function App({ Component, pageProps }) {
  return (
    <Layout>
      <Component {...pageProps} />
    </Layout>
  );
}

페이지가 렌더링 될 때 가장 먼저 실행되는 _app.js에서 Layout component를 사용하면 된다.

 

⚫ Head component


[Seo.js]

import Head from "next/head";

export default function Seo({ title }) {
  return (
    <Head>
      <title>{title} | Next Movies</title>
    </Head>
  );
}

head에 정보를 넣고 싶으면 react-helmet 같은 걸 사용할 필요없이 next.js에서 제공해주는 Head component를 이용하면 된다.

'♠️ Next.js 12' 카테고리의 다른 글

Next.js 12 - getServerSideProps  (0) 2025.03.10
Next.js 12 - public dir, API key 숨기기(redirects, rewrites)  (0) 2025.03.10
Next.js 12 - Global Style  (0) 2025.03.07
Next.js 12 - Styled JSX, unknown property jsx found  (0) 2025.03.04
Next.js 12 - CSS Modules  (0) 2025.03.01
'♠️ Next.js 12' 카테고리의 다른 글
  • Next.js 12 - getServerSideProps
  • Next.js 12 - public dir, API key 숨기기(redirects, rewrites)
  • Next.js 12 - Global Style
  • Next.js 12 - Styled JSX, unknown property jsx found
j2yonghwa
j2yonghwa
Trying to be a fullstack developer 🚀
  • j2yonghwa
    j2yonghwa
    j2yonghwa
  • 전체
    오늘
    어제
    • 분류 전체보기 (156)
      • ⏰ Daily WakaTime (1)
      • 🏖️ 노마드코더 (2)
      • 🍺 Dev Setup (3)
      • 🔭 Tech Info (1)
      • 🚫 Error (1)
      • 📂 라이브러리 (23)
      • ♣️ Next.js 14 (10)
      • ♠️ Next.js 12 (20)
      • 🛸 React Native (12)
      • 🦋 TypeScript (1)
      • 🐍 Python (2)
      • 🌊 TailwindCSS (4)
      • 🧩 SQL (25)
      • 💎 Prisma (5)
      • 🌱 MongoDB (4)
      • 🎯 Redis (1)
      • 🧬 GraphQL (2)
      • 🔥 Firebase (7)
      • 💸 Third-Party Services (2)
      • 🕸️ Web (1)
      • 🏆 코딩테스트 (23)
      • 📙 모딥다 (5)
      • 📗 코테 합격자 되기 -JS- (0)
      • 📘 클린코드 (0)
      • 🍯 꿀팁 🐝 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 깃헙
  • 공지사항

  • 인기 글

  • 태그

    SQL
    라이브러리
    PostgreSQL
    자바스크립트
    dev setup
    tailwindcss
    0레벨
    MySQL
    next.js 12
    mongoDB
    Firebase
    next.js 14
    Prisma
    react router
    React Native
    Python
    모딥다
    코딩테스트 입문
    API
    Next.js
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
j2yonghwa
Next.js 12 - Layout, Head component
상단으로

티스토리툴바