Skip to content

Releases: ceteio/next-layout-loader

v2.0.1

31 Dec 13:23
Compare
Choose a tag to compare

Patch Change

  • Optimise rendering by correctly limiting the maximum number of layout files to those that are actually pre
    sent in the pages/ directory. by @jesstelford in #4

Full Changelog: v2.0.0...v2.0.1

v2.0.0

31 Dec 06:16
Compare
Choose a tag to compare
  • Only require magic in pages/_app, not in every route file.
  • Removed options.layoutsDir. _layout files must now always be in pages/.

Full Changelog: v1.0.0...v2.0.0

v1.0.0

23 Dec 01:24
Compare
Choose a tag to compare

Initial release

yarn add @ceteio/next-layout-loader babel-plugin-codegen babel-plugin-preval

Usage

Add _layout.tsx files with default exports in your pages/ directory:

pages
├── dashboard
│   ├── _layout.tsx
│   └── user
│       ├── _layout.tsx
│       └── index.tsx
├── _layout.tsx
└── index.tsx

For example:

// pages/_layout.tsx
export default function Layout({ children }) {
  return (
    <div style={{ border: "1px solid gray", padding: "1rem" }}>
      <p>
        <code>pages/_layout</code>
      </p>
      {children}
    </div>
  );
}

// To hide this layout component from the router / build pipeline
export const getStaticProps = async () => ({ notFound: true });

Next, load the layout component with
preval &
codegen:

// pages/dashboard/user/index.tsx
const filename = preval`module.exports = __filename`;
const Layout = codegen.require("@ceteio/next-layout-loader", filename);

export default function User() {
  return (
    <Layout>
      <h1>Hello world</h1>
    </Layout>
  );
}

Now, <Layout> is a composition of all _layout.tsx files found in the
pages/ directory from the current file, up to the root (ie;
pages/dashboard/user/_layout.tsx, pages/dashboard/_layout.tsx, and
pages/_layout.tsx).


Full Changelog: https://github.com/ceteio/next-layout-loader/commits/v1.0.0