Project: Dashboard
- React course
- Intermediate
- Lesson 73/80
- 4 min
Review the goal and steps of the dashboard project.
Project: Dashboard
In this project you build a dashboard. Three main pieces: layout and routing, stats widget and add via modal. Each lesson adds one piece.
The layout gives a frame that stays as the page changes. Routing shows content based on the URL. You build both with React Router.
Widgets show data as cards; a modal gives a popup window to add new data. At the end you have a working, modular dashboard.
Tech and structure
The dashboard uses React Router; each route is a page, <Outlet> is where content renders. The StatCard component takes label and value props.
The modal opens and closes via the isOpen state. When the form is submitted, onAdd fires and the modal closes.
Each lesson takes the previous lesson's solution as its starting code; the code grows piece by piece.
Practice Dashboard layout skeleton
Write a DashboardLayout component: a <nav> with two <NavLink>s ("Stats" and "Settings"), then a <main> containing <Outlet />. Place DashboardLayout at path="/" inside <BrowserRouter> and <Routes>. Write a DashboardApp function and export it as default.
Starter code
import { BrowserRouter, Routes, Route, NavLink, Outlet } from "react-router-dom";
// DashboardLayout ve DashboardApp bileşenlerini buraya yazSample solution
import { BrowserRouter, Routes, Route, NavLink, Outlet } from "react-router-dom";
function DashboardLayout() {
return (
<>
<nav>
<NavLink to="/stats">Stats</NavLink>
<NavLink to="/settings">Settings</NavLink>
</nav>
<main>
<Outlet />
</main>
</>
);
}
function DashboardApp() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<DashboardLayout />}>
<Route path="stats" element={<p>Stats</p>} />
<Route path="settings" element={<p>Settings</p>} />
</Route>
</Routes>
</BrowserRouter>
);
}
export default DashboardApp;Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What do we build in the first step?
- Cart and checkout
- Layout and routing Correct answer
- Authentication
- Notifications
Explanation: First we set up the layout and routing skeleton.
2 Router import
import { BrowserRouter, Routes, Route, ____ } from "react-router-dom";
import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";
Explanation: Outlet renders nested route content.
3 Project: Dashboard: match the terms
| Term | Meaning |
|---|---|
layout |
Page frame |
route |
URL mapping |
widget |
Data card |
modal |
Popup window |