AppLayout 만들기
AppLayout.js
next에선 Link href를 통해 페이지를 이동할 수 있다.
import PropTypes from "prop-types";
import Link from "next/link";
import { Menu } from "antd";
const AppLayout = ({ children }) => {
return (
<div>
<Menu mode="horizontal">
<Menu.Item>
<Link href="/">
<a>노드버드</a>
</Link>
</Menu.Item>
<Menu.Item>
<Link href="/profile">
<a>프로필</a>
</Link>
</Menu.Item>
<Menu.Item>
<Link href="/signup">
<a>회원가입</a>
</Link>
</Menu.Item>
</Menu>
{children}
</div>
);
};
AppLayout.propTypes = {
children: PropTypes.node.isRequired,
};
export default AppLayout;
해당 AppLayout을 통해 Layout을 할 수 있다.
import AppLayout from "../components/AppLayout";
const Home = () => {
return (
<>
<AppLayout>
<div>index</div>
</AppLayout>
</>
);
};
export default Home;
pages의 공통 부분을 layout하는법
import PropTypes from "prop-types";
import Head from "next/head";
import "antd/dist/antd.css";
const App = ({ Component }) => {
// pages의 공통 부분
return (
<>
<Head>
<meta charSet="utf-8" />
<title>NodeBird</title>
</Head>
<Component />
</>
);
};
App.PropTypes = {
Component: PropTypes.elementType.isRequired,
};
export default App;
antd - grid
import PropTypes from "prop-types";
import Link from "next/link";
import { Menu, Input, Row, Col } from "antd";
import { useState } from "react";
import UserProfile from "./UserProfile";
import LoginForm from "./LoginForm";
const AppLayout = ({ children }) => {
const [isLoggedIn, setIsLoggendIn] = useState(false);
return (
<div>
...Menu
<Row gutter={8}>{/*gap과 같다.*/}
<Col xs={24} md={6}>
{isLoggedIn ? <UserProfile /> : <LoginForm />}
</Col>
<Col xs={24} md={12}>
{children}
</Col>
<Col xs={24} md={6}>
{/*_blank을쓸때 rel="noreferer noopener"을 써줘야 보안상 좋다.*/}
<a
href="https://velog.io/@abc5259"
target="_blank"
rel="noreferer noopener"
>
Made By LeeJaeHoon
</a>
</Col>
</Row>
</div>
);
};
AppLayout.propTypes = {
children: PropTypes.node.isRequired,
};
export default AppLayout;