리액트에서 프리렌더링을 하려면 여러가지가 필요함
import alias 쓰면 편하다.
최상단 기준으로 @/... 쓰면 된다.
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp;
<html>
<body>
같은 공통 문서 구조를 정의한다.<head>
에 넣기 위해서 이 파일을 커스터마이징할 수 있다.import Document, { Html, Head, Main, NextScript } from 'next/document';
class MyDocument extends Document {
render() {
return (
<Html>
<Head>
{/* 여기에 추가적인 헤드 요소를 넣을 수 있습니다. */}
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;
function HomePage() {
return <div>Welcome to My Next.js App!</div>;
}
export default HomePage;
<Main>
<Main/>
컴포넌트 위치에 삽입된다.<Main/>
은 이 생성된 HTML을 브라우저에 표시하는 역할을 한다.<NextScript/>
예를 들어서
pages (이름 바꾸면 안됨)
ㄴ index.js ( 디폴트 )
ㄴ search.js ==> localhost:3000/search
ㄴ setting.js ==> localhost:3000/setting
ㄴ products
ㄴ index.js ==> localhost:3000/products
ㄴ [id].js ==> /2 , /3, /4, .......
전체 HTML을 다 받아옴