MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Core File Conventions: page.tsx, layout.tsx, template.tsx & not-found.tsx0%
Study Materials
Next.js 15Progress 0%
1.1Next.js 15 Overview & App Router vs Pages Router Architecture1.2Core File Conventions: page.tsx, layout.tsx, template.tsx & not-found.tsx1.3Dynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))1.4Streaming UI with loading.tsx and Suspense Boundaries
HomeTutorialsNext.js 15Core File Conventions: page.tsx, layout.tsx, template.tsx & not-found.tsx
Dynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))

Core File Conventions: page.tsx, layout.tsx, template.tsx & not-found.tsx

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

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.


1. The Core File Hierarchy

1app/
2 ├── layout.tsx # Root Layout (wraps entire application: <html> & <body>)
3 ├── page.tsx # Homepage (/)
4 ├── not-found.tsx # Global 404 handler
5 ├── courses/
6 │ ├── layout.tsx # Nested Layout for /courses/*
7 │ ├── loading.tsx # Loading skeleton for /courses/*
8 │ ├── page.tsx # Courses Catalog (/courses)
9 │ └── [slug]/
10 │ ├── page.tsx # Course Detail (/courses/:slug)
11 │ └── error.tsx# Local Error Boundary

2. layout.tsx: Nested & Persistent Layouts

A layout is UI that is shared between multiple routes. Layouts preserve state, remain interactive, and do not re-render when navigating between sibling routes!

1// app/layout.tsx (Root Layout - Required)
2import type { Metadata } from 'next';
3import Navbar from '@/components/Navbar';
4import Footer from '@/components/Footer';
5import './globals.css';
6 
7export const metadata: Metadata = {
8 title: 'MSK Institute | Premier Tech Education',
9 description: 'Learn full-stack web development and data analytics.'
10};
11 
12export default function RootLayout({
13 children
14}: {
15 children: React.ReactNode;
16}) {
17 return (
18 <html lang="en">
19 <body className="bg-slate-50 text-slate-900 min-h-screen flex flex-col">
20 <Navbar />
21 <main className="flex-1">{children}</main>
22 <Footer />
23 </body>
24 </html>
25 );
26}

3. template.tsx vs layout.tsx

While layout.tsx preserves state across navigation, template.tsx creates a brand-new instance for each child route on navigation:

  • DOM elements are recreated.
  • State is not preserved.
  • Effects (like useEffect) re-sync.
  • Ideal for: Page entrance/exit animations (Framer Motion) or logging per-page views.

4. not-found.tsx: Custom 404 Pages

Next.js renders not-found.tsx when an invalid URL is visited, or when the notFound() function is programmatically triggered:

1// app/courses/[slug]/page.tsx
2import { notFound } from 'next/navigation';
3import { getCourseBySlug } from '@/lib/db';
4 
5export default async function CourseDetailPage({ params }: { params: Promise<{ slug: string }> }) {
6 const { slug } = await params;
7 const course = await getCourseBySlug(slug);
8 
9 if (!course) {
10 notFound(); // Programmatically invokes closest not-found.tsx!
11 }
12 
13 return <div><h1>{course.title}</h1></div>;
14}

Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
Which file is strictly required in the root of the app/ directory and must contain the <html> and <body> tags?
Question 2
What is the fundamental behavioral difference between layout.tsx and template.tsx during client-side navigation?
Question 3
How do you programmatically trigger the not-found.tsx component when an entity does not exist in the database?
Question 4
What prop must every layout.tsx component accept and render?
Question 5
Can a sub-folder (e.g. app/dashboard/settings/) have its own nested layout.tsx?

Next Lesson

Dynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Next.js 15 Overview & App Router vs Pages Router ArchitectureDynamic Routes ([id]), Catch-All Routes ([...slug]) & Route Groups ((group))

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Next.js 15 with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext