This project is a small learning playground that recreates the core ideas of React Router from scratch. Instead of relying on the official library, the app implements a minimal BrowserRouter, Route, and Link to show how client-side routing works with the History API, React context, and component composition. The UI is built with React 19 and Vite for instant dev feedback.
- Tiny
BrowserRouterthat stores the currentURL, listens forpopstate, and exposes routing state through context. <Route>component that renders its children when thepathnamematches thepathprop.<Link>component that callshistory.pushStatefor SPA navigation without a full page reload.- Simple
<Navbar>demonstrating how to add new links and sections such as Home, About, and Contact. - Vite-powered tooling with ESLint so you can iterate quickly while keeping the code tidy.
- Requirements: Node.js 18+ and npm 9+ (Vite’s recommended baseline).
- Install dependencies
npm install
- Start the dev server
Vite prints a local URL (normally
npm run dev
http://localhost:5173). Navigate to/home,/about, or/contactto see each route render.
| Command | Description |
| npm run dev | Start Vite in development mode with HMR. |
React-Router/
├── src/
│ ├── BrowserRouter.jsx # Custom provider that stores the current URL
│ ├── Link.jsx # Pushes new entries to history and updates context
│ ├── Route.jsx # Conditionally renders children based on the pathname
│ ├── Navbar.jsx # Demo navigation using the custom Link component
│ ├── App.jsx # Wires the router and sample routes together
│ └── main.jsx # React entry point created by Vite
└── public/ # Static files served at the root
- Add more
<Route path="/your-path">blocks inApp.jsx(or any component nested insideBrowserRouter) to display additional sections. - Style the navigation by replacing the placeholder markup in
Navbar.jsxwith your preferred layout. - Enhance
<Route>to support wildcard matching, nested routes, query params, or fallback routes to mirror the real React Router feature set.
This router intentionally keeps the implementation light: there is no route prioritization, no lazy loading, and no error boundaries. Treat it as an educational foundation. Ideas for future exploration include adding hash-based routing, scroll restoration, link "active" states, or turning the helpers into an npm package.