ixartz / Next-js-Boilerplate

🚀🎉📚 Boilerplate and Starter for Next.js 14+ with App Router and Page Router support, Tailwind CSS 3.4 and TypeScript ⚡️ Made with developer experience first: Next.js + TypeScript + ESLint + Prettier + Husky + Lint-Staged + Jest + Testing Library + Cypress + Storybook + Commitlint + VSCode + Netlify + PostCSS + Tailwind CSS

Home Page:https://nextjs-boilerplate.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use getLayout function to customize layout

riolly opened this issue · comments

As it's written on the official docs.

// pages/index.js

import Layout from '../components/layout'
import NestedLayout from '../components/nested-layout'

export default function Page() {
  return {
    /** Your content */
  }
}

Page.getLayout = function getLayout(page) {
  return (
    <Layout>
      <NestedLayout>{page}</NestedLayout>
    </Layout>
  )
}
// pages/_app.js

export default function MyApp({ Component, pageProps }) {
  // Use the layout defined at the page level, if available
  const getLayout = Component.getLayout || ((page) => page)

  return getLayout(<Component {...pageProps} />)
}

@riolly, this also something I use personally but I didn't integrate it. Should we?

We use that pattern to avoid rerendering the layout component when navigating to a page with the same layout. (mimicking client-side navigation)
And I think those who use this template have been familiar with next.js and (the other tech stack inside it) and will end up in that situation also.

commented

I think the getLayout pattern should be implemented.

I think we can directly switch to the app directory when the feature come out from the beta and there are still some missing feature: https://beta.nextjs.org/docs/app-directory-roadmap#planned-features

Hope the beta won't last too long.

Planning to switch directly to app directory when the feature come out from the beta.