Skip to main content

Lesson 9 of 10

Mini Project: Multi-Page Admin Dashboard

Build a complete multi-page admin dashboard wiring together all React Router concepts: nested layouts, protected routes, dynamic user detail pages, search params for filtering, a 404 page, and error boundaries.

60 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Complete Multi-Page Dashboard

Complete Multi-Page Dashboard
import { useState } from 'react';
import {
  BrowserRouter, Routes, Route, Navigate, NavLink,
  Outlet, Link, useNavigate, useParams, useSearchParams, useLocation
} from 'react-router-dom';

// ---- Types ----
interface User { id: string; name: string; email: string; role: 'admin' | 'user'; status: 'active' | 'inactive'; }
const MOCK_USERS: User[] = [
  { id: '1', name: 'Alice Johnson', email: 'alice@example.com', role: 'admin', status: 'active' },
  { id: '2', name: 'Bob Smith', email: 'bob@example.com', role: 'user', status: 'active' },
  { id: '3', name: 'Carol White', email: 'carol@example.com', role: 'user', status: 'inactive' },
];

// ---- Auth context (simplified) ----
function useAuth() {
  const [isAuthenticated] = useState(true); // assume logged-in for demo
  return { isAuthenticated, user: MOCK_USERS[0] };
}

// ---- Protected Route ----
function ProtectedRoute() {
  const { isAuthenticated } = useAuth();
  const location = useLocation();
  if (!isAuthenticated) return <Navigate to="/login" state={{ from: location }} replace />;
  return <Outlet />;
}

// ---- Root Layout ----
function RootLayout() {
  return (
    <div style={{ fontFamily: 'system-ui', background: '#0f172a', minHeight: '100vh', color: 'white' }}>
      <Outlet />
    </div>
  );
}

// ---- Dashboard Layout with Sidebar ----
function DashboardLayout() {
  const { user } = useAuth();
  const navigate = useNavigate();
  const navStyle = ({ isActive }: { isActive: boolean }) => ({
    display: 'block', padding: '10px 16px', borderRadius: 8,
    background: isActive ? '#229c6b' : 'transparent',
    color: isActive ? 'white' : '#94a3b8',
    textDecoration: 'none', marginBottom: 4,
    fontSize: 14, fontWeight: isActive ? 600 : 400,
  });

  return (
    <div style={{ display: 'flex', height: '100vh' }}>
      {/* Sidebar */}
      <aside style={{ width: 220, background: '#1e293b', padding: '20px 12px', flexShrink: 0 }}>
        <div style={{ padding: '0 8px 20px', borderBottom: '1px solid #334155', marginBottom: 12 }}>
          <p style={{ margin: 0, fontWeight: 700, color: '#f1f5f9' }}>Admin Panel</p>
          <p style={{ margin: '4px 0 0', fontSize: 12, color: '#64748b' }}>{user?.name}</p>
        </div>
        <NavLink to="/dashboard" end style={navStyle}>📊 Overview</NavLink>
        <NavLink to="/dashboard/users" style={navStyle}>👥 Users</NavLink>
        <NavLink to="/dashboard/settings" style={navStyle}>⚙️ Settings</NavLink>
        <button
          onClick={() => navigate('/login', { replace: true })}
          style={{ width: '100%', marginTop: 'auto', background: 'transparent', border: '1px solid #334155', color: '#94a3b8', padding: '8px 16px', borderRadius: 8, cursor: 'pointer', fontSize: 13, position: 'absolute', bottom: 20, width: 196 }}
        >
          Sign Out
        </button>
      </aside>

      {/* Main content */}
      <main style={{ flex: 1, overflow: 'auto' }}>
        <Outlet />
      </main>
    </div>
  );
}

// ---- Pages ----
function Overview() {
  return (
    <div style={{ padding: 32 }}>
      <h1 style={{ margin: '0 0 24px', fontSize: 24 }}>Dashboard Overview</h1>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16 }}>
        {[
          { label: 'Total Users', value: MOCK_USERS.length, color: '#229c6b' },
          { label: 'Active Users', value: MOCK_USERS.filter(u => u.status === 'active').length, color: '#10b981' },
          { label: 'Admins', value: MOCK_USERS.filter(u => u.role === 'admin').length, color: '#f59e0b' },
        ].map(stat => (
          <div key={stat.label} style={{ background: '#1e293b', borderRadius: 12, padding: 20, borderTop: `3px solid ${stat.color}` }}>
            <p style={{ margin: '0 0 8px', color: '#94a3b8', fontSize: 13 }}>{stat.label}</p>
            <p style={{ margin: 0, fontSize: 28, fontWeight: 700 }}>{stat.value}</p>
          </div>
        ))}
      </div>
    </div>
  );
}

function UserList() {
  const [searchParams, setSearchParams] = useSearchParams();
  const filter = searchParams.get('status') ?? 'all';

  const filtered = MOCK_USERS.filter(u => filter === 'all' || u.status === filter);

  return (
    <div style={{ padding: 32 }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 24 }}>
        <h1 style={{ margin: 0, fontSize: 24 }}>Users</h1>
        <select
          value={filter}
          onChange={e => setSearchParams(prev => { prev.set('status', e.target.value); return prev; })}
          style={{ background: '#334155', border: 'none', color: 'white', padding: '8px 12px', borderRadius: 8, cursor: 'pointer' }}
        >
          <option value="all">All</option>
          <option value="active">Active</option>
          <option value="inactive">Inactive</option>
        </select>
      </div>
      <div style={{ background: '#1e293b', borderRadius: 12, overflow: 'hidden' }}>
        {filtered.map(user => (
          <Link
            key={user.id}
            to={user.id}
            style={{ display: 'flex', alignItems: 'center', padding: '14px 20px', borderBottom: '1px solid #334155', textDecoration: 'none', color: 'white' }}
          >
            <div style={{ width: 36, height: 36, borderRadius: '50%', background: '#229c6b', display: 'flex', alignItems: 'center', justifyContent: 'center', marginRight: 12, fontWeight: 700 }}>
              {user.name[0]}
            </div>
            <div style={{ flex: 1 }}>
              <p style={{ margin: 0, fontWeight: 600 }}>{user.name}</p>
              <p style={{ margin: 0, fontSize: 13, color: '#64748b' }}>{user.email}</p>
            </div>
            <span style={{ fontSize: 12, padding: '3px 10px', borderRadius: 999, background: user.status === 'active' ? '#064e3b' : '#450a0a', color: user.status === 'active' ? '#6ee7b7' : '#fca5a5' }}>
              {user.status}
            </span>
          </Link>
        ))}
      </div>
    </div>
  );
}

function UserDetail() {
  const { userId } = useParams<{ userId: string }>();
  const navigate = useNavigate();
  const user = MOCK_USERS.find(u => u.id === userId);

  if (!user) return <Navigate to="/404" replace />;

  return (
    <div style={{ padding: 32 }}>
      <button onClick={() => navigate(-1)} style={{ background: 'transparent', border: '1px solid #334155', color: '#94a3b8', padding: '8px 16px', borderRadius: 8, cursor: 'pointer', marginBottom: 24 }}>
        ← Back to Users
      </button>
      <div style={{ background: '#1e293b', borderRadius: 12, padding: 24 }}>
        <div style={{ width: 64, height: 64, borderRadius: '50%', background: '#229c6b', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 24, fontWeight: 700, marginBottom: 16 }}>
          {user.name[0]}
        </div>
        <h1 style={{ margin: '0 0 4px', fontSize: 22 }}>{user.name}</h1>
        <p style={{ color: '#94a3b8', margin: '0 0 16px' }}>{user.email}</p>
        <p><strong>Role:</strong> {user.role}</p>
        <p><strong>Status:</strong> {user.status}</p>
      </div>
    </div>
  );
}

function Settings() {
  return <div style={{ padding: 32 }}><h1>Settings</h1><p style={{ color: '#94a3b8' }}>Configuration options here.</p></div>;
}

function NotFound() {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', height: '100vh', textAlign: 'center', padding: 32 }}>
      <p style={{ fontSize: 80, margin: 0 }}>🚫</p>
      <h1 style={{ fontSize: 32, margin: '16px 0 8px' }}>404 - Not Found</h1>
      <p style={{ color: '#94a3b8', marginBottom: 24 }}>The page you're looking for doesn't exist.</p>
      <Link to="/dashboard" style={{ background: '#229c6b', color: 'white', padding: '10px 24px', borderRadius: 8, textDecoration: 'none', fontWeight: 600 }}>
        Go to Dashboard
      </Link>
    </div>
  );
}

// ---- Router Assembly ----
export default function AdminDashboardApp() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<RootLayout />}>
          <Route index element={<Navigate to="/dashboard" replace />} />

          {/* Protected routes */}
          <Route element={<ProtectedRoute />}>
            <Route path="dashboard" element={<DashboardLayout />}>
              <Route index element={<Overview />} />
              <Route path="users" element={<UserList />} />
              <Route path="users/:userId" element={<UserDetail />} />
              <Route path="settings" element={<Settings />} />
            </Route>
          </Route>

          <Route path="*" element={<NotFound />} />
        </Route>
      </Routes>
    </BrowserRouter>
  );
}

What This Project Demonstrates

  • Nested layouts - `RootLayout` → `DashboardLayout` → page components, each layer adding UI that persists
  • Protected routes - `ProtectedRoute` wrapper with `useLocation` to preserve the intended destination
  • Dynamic segments - `/dashboard/users/:userId` page that reads `useParams` and handles not-found case
  • Search params - filter users by status with `useSearchParams`, updating without page reload
  • Programmatic navigation - `navigate(-1)` for back button, `navigate('/login', { replace: true })` for logout
  • NavLink active styling - sidebar highlights the current route with color and font-weight
  • 404 catch-all - `<Route path="*">` catches any unmatched URL

Tip

Tip

Practice Mini Project MultiPage Admin Dashboard in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and flow for Mini Project: Multi-Page Admin Dashboard

Practice Task

Note

Practice Task - (1) Write a working example of Mini Project MultiPage Admin Dashboard from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with Mini Project MultiPage Admin Dashboard is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react code.

Key Takeaways

  • Build a complete multi-page admin dashboard wiring together all React Router concepts: nested layouts, protected routes, dynamic user detail pages, search params for filtering, a 404 page, and error boundaries.
  • Nested layouts - `RootLayout` → `DashboardLayout` → page components, each layer adding UI that persists
  • Protected routes - `ProtectedRoute` wrapper with `useLocation` to preserve the intended destination
  • Dynamic segments - `/dashboard/users/:userId` page that reads `useParams` and handles not-found case

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done