패스트컴퍼스 강의를 듣고 (제가 알아보게..) 정리한 내용입니다.
- <a href="/posts/first-post"> 첫번째 글(A)</a>
- <Link href="/posts/first-post">첫번째 글(Link)</Link>
- 태그에 background-color 를 주고 페이지 변화 차이를 본다.
- 개발자 도구의 네트워크 탭에서 불러오는 파일들의 차이를 본다.
A태그는 주소창에 새로운 링크를 치는 것과 동일, 페이지를 새로 불러온다.
Link태그는 페이지 안에서 필요한 데이터만 추가적으로 가져온다.
- <img src="/imgaes/profile.jpg" alt="dorikoo" />
- <Image src="/images/profile.jpg" width={150} height={150} alt="dorikoo" />
특징
- /images/profile.jpg 로 받아오고 있다.
- image/jpeg 파일이다.
./layout.module.css 라는 CSS 모듈을 만들어 보자
- components 폴더를 생성
- Layout.js / layout.module.css 파일을 생성 해준다.
import Head from 'next/head';
import Image from 'next/image';
import styles from './layout.module.css';
import utilStyles from '../styles/utils.module.css';
import Link from 'next/link';
const name = 'Your Name';
export const siteTitle = 'Next.js Sample Website';
export default function Layout({ children, home }) {
return (
<div className={styles.container}>
<Head>
<link rel="icon" href="/favicon.ico" />
<meta
name="description"
content="Learn how to build a personal website using Next.js"
/>
<meta
property="og:image"
content={`https://og-image.vercel.app/${encodeURI(
siteTitle,
)}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.vercel.com%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg`}
/>
<meta name="og:title" content={siteTitle} />
<meta name="twitter:card" content="summary_large_image" />
</Head>
<header className={styles.header}>
{home ? (
<>
<Image
priority
src="/images/profile.jpg"
className={utilStyles.borderCircle}
height={144}
width={144}
alt=""
/>
<h1 className={utilStyles.heading2Xl}>{name}</h1>
</>
) : (
<>
<Link href="/">
<Image
priority
src="/images/profile.jpg"
className={utilStyles.borderCircle}
height={108}
width={108}
alt=""
/>
</Link>
<h2 className={utilStyles.headingLg}>
<Link href="/" className={utilStyles.colorInherit}>
{name}
</Link>
</h2>
</>
)}
</header>
<main>{children}</main>
{!home && (
<div className={styles.backToHome}>
<Link href="/">← Back to home</Link>
</div>
)}
</div>
);
}
.container {
max-width: 36rem;
padding: 0 1rem;
margin: 3rem auto 6rem;
}
.header {
display: flex;
flex-direction: column;
align-items: center;
}
.backToHome {
margin: 3rem 0 0;
}
styles 폴더를 생성 후 utils.module.css 를 만들어보자
.heading2Xl {
font-size: 2.5rem;
line-height: 1.2;
font-weight: 800;
letter-spacing: -0.05rem;
margin: 1rem 0;
}
.headingXl {
font-size: 2rem;
line-height: 1.3;
font-weight: 800;
letter-spacing: -0.05rem;
margin: 1rem 0;
}
.headingLg {
font-size: 1.5rem;
line-height: 1.4;
margin: 1rem 0;
}
.headingMd {
font-size: 1.2rem;
line-height: 1.5;
}
.borderCircle {
border-radius: 9999px;
}
.colorInherit {
color: inherit;
}
.padding1px {
padding-top: 1px;
}
.list {
list-style: none;
padding: 0;
margin: 0;
}
.listItem {
margin: 0 0 1.25rem;
}
.lightText {
color: #666;
}
- pages/ 안에 _app.js 를 생성해준다.
- styles/ 안에 global.css를 생성해준다.
import '../styles/globals.css'
export default function App({Component, pageProps}){
return <Component {...pageProps} />
}
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu,
Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
line-height: 1.6;
font-size: 18px;
}
* {
box-sizing: border-box;
}
a {
color: #0070f3;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
img {
max-width: 100%;
display: block;
}
참조 (global.css) - https://nextjs.org/learn/basics/assets-metadata-css/global-styles
참조 (Profile Layout) - https://nextjs.org/learn/basics/assets-metadata-css/polishing-layout