NextJS ๊ณต์๋ฌธ์ ๐
navigation
์ด๋ footer
์ ๊ฐ์ ๊ณตํต ๋ ์ด์์์ Layout component
๋ก ๋ง๋ค๊ณ _app.tsx
์ import
ํ์ฌ ๋ ๋๋งํ๋ค.
Example
// components/Layout.tsx
import React from "react";
import NavBar from "./NavBar";
const Layout = ({ children }: React.PropsWithChildren) => {
return (
<div>
<NavBar />
<div>{children}</div>
</div>
);
};
export default Layout;
// components/Layout.tsx
import React from "react";
import NavBar from "./NavBar";
const Layout = ({ children }: React.PropsWithChildren) => {
return (
<div>
<NavBar />
<div>{children}</div>
</div>
);
};
export default Layout;
Head component
์ children
์ผ๋ก ๋ค์ด๊ฐ๋ ํ๊ทธ๋ค์ด html
์ head
์์ ๋ณด์ฌ์ง ๊ฒ์ด๋ค.
Head component๋ html์ head ํ๊ทธ์ ๋น์ทํ ์ญํ ์ ํ๋ค.
// components/CustomHead.tsx
import Head from "next/head";
interface CustomHeadProps {
title: string;
}
const CustomHead = ({ title }: CustomHeadProps) => {
return (
<Head>
<title>{title} | Next Movies</title>
</Head>
);
};
export default CustomHead;
// pages/index.tsx
import type { NextPage } from "next";
import CustomHead from "../components/CustomHead";
const Home: NextPage = () => {
return (
<div>
<CustomHead title="Home" />
<h1>Home</h1>
</div>
);
};
export default Home;
// pages/about.tsx
import type { NextPage } from "next";
import CustomHead from "../components/CustomHead";
const About: NextPage = () => {
return (
<div>
<CustomHead title="About" />
<h1>About</h1>
</div>
);
};
export default About;