layout file

This commit is contained in:
Timur Ercan
2022-12-06 13:45:23 +01:00
parent 1e164090b3
commit f850729356
3 changed files with 39 additions and 78 deletions

View File

@ -0,0 +1,15 @@
import React, { ReactNode } from "react";
interface Props {
children?: any;
}
export default function Layout({ children }: Props) {
return (
<>
<div>Header</div>
<main>{children}</main>
<div>Footer</div>
</>
);
}

View File

@ -1,6 +1,16 @@
import '../styles/globals.css' import { ReactElement, ReactNode } from "react";
import type { AppProps } from 'next/app' import type { AppProps } from "next/app";
import { NextPage } from "next";
export default function App({ Component, pageProps }: AppProps) { export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
return <Component {...pageProps} /> getLayout?: (page: ReactElement) => ReactNode;
};
type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};
export default function App({ Component, pageProps }: AppPropsWithLayout) {
const getLayout = Component.getLayout || ((page: any) => page);
return getLayout(<Component {...pageProps} />);
} }

View File

@ -1,77 +1,13 @@
import Head from "next/head"; import type { ReactElement } from "react";
import Image from "next/image"; import Layout from "../components/layout";
import styles from "../styles/Home.module.css"; import type { NextPageWithLayout } from "./_app";
export async function getStaticProps(context: any) { const Page: NextPageWithLayout = () => {
return { return <p>hello world</p>;
props: {}, // will be passed to the page component as props };
};
}
export default function Home() { Page.getLayout = function getLayout(page: ReactElement) {
return ( return <Layout>{page}</Layout>;
<div className={styles.container}> };
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}> export default Page;
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<p className={styles.description}>
Get started by editing{" "}
<code className={styles.code}>pages/index.tsx</code>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation &rarr;</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/canary/examples"
className={styles.card}
>
<h2>Examples &rarr;</h2>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
className={styles.card}
>
<h2>Deploy &rarr;</h2>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{" "}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
);
}