Layouts and Templates
Last updated
What is Layouts and Templates?
Layouts and templates provide a way to share UI elements across multiple pages, maintaining state and avoiding unnecessary re-renders. Layouts wrap around pages, persisting across route changes to preserve things like navigation bars or sidebars.
Templates are similar to layouts in that they wrap each child layout or page. Unlike layouts that persist across routes and maintain state, templates create a new instance for each of their children on navigation. This means that when a user navigates between routes that share a template, a new instance of the component is mounted, DOM elements are recreated, state is not preserved, and effects are re-synchronized.
Free resources to learn Layouts and Templates
- Official docsLayouts for App Router
- Official docsLayouts for Pages Router
- Official docsTemplates for App Router
- ArticleA guide to Next.js layouts and nested layouts
- VideoNext.js 15 Tutorial - Layouts
- VideoNext.js 15 Tutorial - Templates
More in stage 9: Layouts and Templates
Layouts and Templates: common questions
Can I learn Layouts and Templates in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Layouts and Templates in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Layouts and Templates tutorial for beginners?
It is lesson 20 of 94 in the free Next.js roadmap, in stage 9, Layouts and Templates. If you are new to Next.js, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.