From cf7c85e3bae4a8176e66f21b3d825e7b146e43d6 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Thu, 1 Oct 2020 21:30:08 -0500 Subject: [PATCH] Added shared layout with _app --- components/core/Layout/Layout.tsx | 1 + pages/_app.tsx | 11 ++++++++++- pages/index.tsx | 8 +++----- pages/product/[slug].tsx | 16 +++++++--------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/components/core/Layout/Layout.tsx b/components/core/Layout/Layout.tsx index 246028878..8dec4a719 100644 --- a/components/core/Layout/Layout.tsx +++ b/components/core/Layout/Layout.tsx @@ -14,6 +14,7 @@ interface Props { const CoreLayout: FunctionComponent = ({ className, children }) => { const rootClassName = cn(s.root, className) const { displaySidebar } = useUI() + return (
<>{children} + export default function MyApp({ Component, pageProps }: AppProps) { - return + const Layout = (Component as any).Layout || Noop + + return ( + + + + ) } diff --git a/pages/index.tsx b/pages/index.tsx index 6e5a6b5f5..597943825 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -14,9 +14,7 @@ export default function Home({ products, }: InferGetStaticPropsType) { console.log('PRODUCTS', products) - return ( - - - - ) + return } + +Home.Layout = Layout diff --git a/pages/product/[slug].tsx b/pages/product/[slug].tsx index e362daa1f..ed06a97fa 100644 --- a/pages/product/[slug].tsx +++ b/pages/product/[slug].tsx @@ -43,7 +43,7 @@ export async function getStaticPaths() { } } -export default function Home({ +export default function Slug({ product, productData, }: InferGetStaticPropsType) { @@ -51,13 +51,11 @@ export default function Home({ const router = useRouter() - return ( - - {router.isFallback ? ( -

Loading...

- ) : ( - - )} -
+ return router.isFallback ? ( +

Loading...

+ ) : ( + ) } + +Slug.Layout = Layout