Layout navigation behavior helps keep parts of your page, like headers or menus, visible while you move between pages. This makes your app feel faster and smoother.
Layout navigation behavior in NextJS
export default function RootLayout({ children }) { return ( <html lang="en"> <body> <Header /> {children} <Footer /> </body> </html> ) }
The RootLayout wraps all pages and keeps layout elements persistent.
The {children} represents the current page content inside the layout.
export default function RootLayout({ children }) { return ( <html lang="en"> <body> <nav>Menu</nav> {children} </body> </html> ) }
export default function RootLayout({ children }) { return ( <html lang="en"> <body> <Header /> <main>{children}</main> <Footer /> </body> </html> ) }
This RootLayout component keeps the header with navigation links visible on every page. The page content changes inside the <main> area when you navigate.
import Link from 'next/link' function Header() { return ( <header style={{ padding: '1rem', backgroundColor: '#eee' }}> <nav> <Link href="/">Home</Link> | <Link href="/about">About</Link> </nav> </header> ) } export default function RootLayout({ children }) { return ( <html lang="en"> <body> <Header /> <main style={{ padding: '1rem' }}>{children}</main> </body> </html> ) }
Layouts in Next.js 14+ use the app/ folder and special layout.js files.
Navigation inside layouts is fast because only the page content updates, not the whole layout.
Use semantic HTML elements like <header>, <nav>, and <main> for better accessibility.
Layouts keep parts of your page visible during navigation for a smooth experience.
Use RootLayout to wrap all pages and share common UI like headers or footers.
Next.js updates only the page content inside layouts, making navigation faster.