Next.js uses a special file system convention inside the app directory. Naming files with reserved conventions (page, layout, template, loading, error, not-found) automatically wires up routing, nested layouts, state persistence, and error boundaries.
layout.tsx: Nested & Persistent LayoutsA layout is UI that is shared between multiple routes. Layouts preserve state, remain interactive, and do not re-render when navigating between sibling routes!
template.tsx vs layout.tsxWhile layout.tsx preserves state across navigation, template.tsx creates a brand-new instance for each child route on navigation:
useEffect) re-sync.not-found.tsx: Custom 404 PagesNext.js renders not-found.tsx when an invalid URL is visited, or when the notFound() function is programmatically triggered:
app/ directory and must contain the <html> and <body> tags?layout.tsx and template.tsx during client-side navigation?not-found.tsx component when an entity does not exist in the database?layout.tsx component accept and render?app/dashboard/settings/) have its own nested layout.tsx?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.