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
Defining Routes, Route Layouts, and Outlets0%
Study Materials
React.js for IntermediateProgress 0%
1.1Component Reusability and Polymorphic Components1.2Render Props Pattern in Modern React1.3Higher-Order Components vs Modern Hooks1.4Compound Components Pattern Explained
4.1Client-Side Routing Architecture with React Router4.2Defining Routes, Route Layouts, and Outlets4.3Dynamic URL Parameters with useParams4.4Programmatic Navigation and useSearchParams
HomeTutorialsReact.js for IntermediateDefining Routes, Route Layouts, and Outlets
Dynamic URL Parameters with useParams

Defining Routes, Route Layouts, and Outlets

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

1. Nested Routing and Shared Layouts

Real-world web applications share consistent structural layouts across multiple pages:

  • A shared top navigation bar and global footer.
  • A dashboard sidebar with sub-navigation links.
  • Consistent breadcrumb trails.

Instead of duplicating the <Navbar /> and <Sidebar /> inside every individual page component, modern routing employs Nested Routes and Shared Layouts.

1 Application Layout (Navbar & Footer)
2 │
3 ┌─────────────────────┴─────────────────────┐
4 ▼ ▼
5 Home Route Dashboard Layout (Sidebar)
6 (/) │
7 ┌──────────┴──────────┐
8 ▼ ▼
9 Analytics Page Settings Page
10 (/dashboard/analytics) (/dashboard/settings)

2. The <Outlet> Component

In React Router, <Outlet> acts as a placeholder or dynamic portal inside a parent layout component.

When a child route matches the active URL, React Router renders that child component directly inside the parent layout's <Outlet />:

1// src/layouts/RootLayout.jsx
2import React from 'react';
3import { Outlet, NavLink } from 'react-router-dom';
4 
5export default function RootLayout() {
6 return (
7 <div className="site-wrapper">
8 {/* Shared Header across all pages */}
9 <header className="global-header">
10 <h1 className="logo">MSK Institute</h1>
11 <nav className="nav-links">
12 <NavLink to="/">Home</NavLink>
13 <NavLink to="/courses">Courses</NavLink>
14 <NavLink to="/dashboard">Dashboard</NavLink>
15 </nav>
16 </header>
17 
18 {/* Dynamic Slot: Child routes render here! */}
19 <main className="page-content">
20 <Outlet />
21 </main>
22 
23 {/* Shared Footer across all pages */}
24 <footer className="global-footer">
25 <p>© 2026 MSK Institute of Technology. All rights reserved.</p>
26 </footer>
27 </div>
28 );
29}

3. Nesting Routes in the Route Configuration

In your route definitions, nest child <Route> elements inside parent layout <Route> tags:

1import React from 'react';
2import { BrowserRouter, Routes, Route } from 'react-router-dom';
3import RootLayout from './layouts/RootLayout';
4import DashboardLayout from './layouts/DashboardLayout';
5import HomePage from './pages/HomePage';
6import CoursesPage from './pages/CoursesPage';
7import AnalyticsPage from './pages/AnalyticsPage';
8import SettingsPage from './pages/SettingsPage';
9import NotFoundPage from './pages/NotFoundPage';
10 
11export default function App() {
12 return (
13 <BrowserRouter>
14 <Routes>
15 {/* Parent Root Layout */}
16 <Route path="/" element={<RootLayout />}>
17 {/* Index Route: renders when URL matches exact parent path "/" */}
18 <Route index element={<HomePage />} />
19 <Route path="courses" element={<CoursesPage />} />
20 
21 {/* Nested Sub-Layout: /dashboard */}
22 <Route path="dashboard" element={<DashboardLayout />}>
23 <Route index element={<AnalyticsPage />} />
24 <Route path="analytics" element={<AnalyticsPage />} />
25 <Route path="settings" element={<SettingsPage />} />
26 </Route>
27 
28 {/* 404 Catch-All Route */}
29 <Route path="*" element={<NotFoundPage />} />
30 </Route>
31 </Routes>
32 </BrowserRouter>
33 );
34}

4. Index Routes and 404 Catch-Alls

  • Index Routes (<Route index element={<Home />} />): An index route renders in the parent layout's <Outlet /> when the user is at the exact parent URL path (/ or /dashboard), without appending extra route segments.
  • *Catch-All 404 Routes (`<Route path="" element={<NotFound />} />):** The asterisk wildcard *` matches any URL that failed to match any defined route, displaying a user-friendly 404 page.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the primary role of the <Outlet> component in React Router?
Question 2
How do you define a 404 "Page Not Found" route in React Router v6?
Question 3
What is an "Index Route" (<Route index element={<Home />} />)?
Question 4
What is the primary architectural benefit of nested routing with shared layouts?
Question 5
If a child route path is defined as path="analytics" inside a parent with path="dashboard", what full URL matches it?
Next Lesson

Dynamic URL Parameters with useParams

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

Related Lessons

Previous LessonNext Lesson
Client-Side Routing Architecture with React RouterDynamic URL Parameters with useParams

Practice Quiz

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

Mentor-Led Practical Training

Master React.js for Intermediate 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