Skip to content

adriano-tirloni/next-layouts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NextLayouts

Small util for persistent layouts in Next.Js

//_app.js
import NextLayout from 'NextLayouts'
import layoutsList from "../path/to/layouts"
NextLayout.layoutsList = layoutsList

//layoutList should be a index object of layouts { BaseLayout, CustomLayout }


class MyApp extends App {
  render() {
    const { Component, pageProps, router } = this.props
    return NextLayout(Component, pageProps)
  }
}

NextJs Page example:

const Homepage = () => <p>homepage</p>

Homepage.layout = 'BaseLayout'

export default homepage

NextJs Nested Layout Page using dot notation example:

const Homepage = () => <p>homepage</p>

Homepage.layout = 'BaseLayout.WrapperLayout.AnotherLayout'

export default homepage

Layouts themselves can have layouts; Watchout for loops between layouts calling each other.

const Otherlay = ({ children }) => (
  <>
    <div>{children}</div>
  </>
);
Otherlay.layout = 'BaseLayout'
export default Otherlay;

About

Small util for persistent layouts on NextJs

Resources

License

Stars

Watchers

Forks

Packages

No packages published