A small interactive simulator demonstrating how browser navigation and history work using two stacks (back and forward). This app is built with React + TypeScript and uses Vite for bundling. It's intended as an educational tool and lightweight demo for learning how browser history can be implemented using stack data structures.
Key goals:
- Visualize navigation between pages with Back / Forward behavior.
- Inspect the internal stacks used to implement history.
- Offer an interactive address bar and page view for experimentation.
Run the app locally (see below) and open http://localhost:5173 in your browser. The UI provides an address bar, navigation toolbar (Back, Forward, Visit), a page view, and a stacks inspector showing the current back/forward stacks.
Live demo (deployed to GitHub Pages):
React Browser History Simulator
(Note: the site will be live after you run npm run deploy or when your CI workflow publishes the gh-pages branch.)
- Interactive address bar to navigate to custom URLs.
- Back / Forward navigation implemented with two stacks.
- Visual inspector showing the contents of each stack.
- Minimal UI built with Tailwind CSS.
- React 19 (functional components + hooks)
- TypeScript
- Vite (dev server + build)
- Tailwind CSS
- ESLint for linting
- Node.js 18+ recommended
- A package manager (pnpm, npm or yarn). The project uses standard npm scripts.
Open a terminal in the project root and run:
npm installStart the dev server (Vite):
npm run devOpen http://localhost:5173
To produce a production build and preview it locally:
npm run build
npm run previewRun ESLint across the project:
npm run lintThis project uses Vitest for unit tests. Tests are organized per-feature. Each feature can provide its own test setup file at __tests__/setup.ts next to its tests (for example src/features/navigation/__tests__/setup.ts).
Run tests with:
npm run testTo run tests once (CI mode):
npm run test -- --run- The Vitest configuration is in
vitest.config.tsand uses a DOM-like environment. Per-featuresetup.tsfiles are picked up manually by tests in those folders. - If you add a global test setup file, add it to
vitest.config.tsundertest.setupFiles.
Feature-based (vertical slices) with a single navigation slice.
Important files and folders:
src/main.tsx- App bootstrap and React entrypointsrc/app/App.tsx- Top-level app layoutsrc/app/features/navigation- Core feature: hooks, UI, and small utilitiesstate/useBrowserHistory.ts- Hook implementing the two-stack browser history logicui/AddressBar.tsx- Address bar componentui/BrowserHistorySimulator.tsx- Main simulator UIui/HistoryToolbar.tsx- Back / Forward / Visit controlsui/PageView.tsx- Simple page rendererui/StacksInspector.tsx- Visualizes back/forward stacks
Other repo files:
vite.config.ts- Vite configurationtsconfig*.json- TypeScript configurationeslint.config.js- ESLint configuration
Overview:
This project demonstrates an implementation of browser-like history using two stacks:
- backStack: holds previously visited pages. Pushing a new page clears the forward stack.
- forwardStack: holds pages popped from backStack when navigating backward. Visiting a new page clears forwardStack.
Contract (what the hook provides):
- Inputs: a starting URL, and calls to visit(url), goBack(), goForward().
- Outputs: the current URL, boolean flags indicating whether back/forward are possible, and the two stacks for inspection.
Edge cases considered:
- Visiting the same URL twice — the stacks update predictably (depending on implementation choices).
- Attempting to go back when there is no history — operation is a no-op and guard flags prevent errors.
- Large navigation sequences — stacks grow linearly with visited pages.
This is intentionally small and educational; it doesn't attempt to replicate full browser semantics (history.replaceState, scroll/restoration, entries with state objects, etc.).
Contributions are welcome. If you'd like to contribute:
- Fork the repository.
- Create a branch for your feature/fix:
git checkout -b feat/name - Install dependencies and run the dev server.
- Add tests or documentation where appropriate.
- Open a pull request describing your changes.
Please follow existing code style, TypeScript typing, and lint rules. Run npm run lint before opening a PR.
This project is provided under the MIT License. See the LICENSE file for details.
Copyright © 2025, Kaissar Mouelhi