How webdevsimplified/my-own-react-router works
Project Type and Purpose
• This is a single‑page application (SPA) built with React and TypeScript, bundled by Vite.
• Features client‑side routing (custom router in src/router), HMR for development, and a file‑based pages system under src/pages.
Main Components
a. Development Environment
• Vite Dev Server
• React Fast Refresh plugin (Babel or SWC)
• ESLint (optional linting service)
b. Build Pipeline
• Vite bundler (rollup under the hood)
• TypeScript compiler (tsconfig.app.json)
c. Runtime (Browser)
• index.html (entry HTML)
• main.tsx (React root)
• Router subsystem (RouterProvider, routeParser, defineRoute)
• Page components under src/pages
• Shared layout components (src/pages/layout.tsx)
d. Configuration & Metadata
• package.json / package-lock.json
• tsconfig.json / tsconfig.node.json / tsconfig.app.json
• vite.config.ts
• eslint.config.js
Relationships and Data Flow
• During development:
Developer edits files → Vite watches FS → TypeScript + React plugin transpile → HMR pushes updates to Browser
• On build:
Vite reads vite.config.ts → applies plugins → bundles TSX → outputs static assets → served by any HTTP server
• At runtime in Browser:
index.html loads bundled JS → main.tsx mounts React tree → RouterProvider reads URL → routeParser selects Page component → renders Page via Outlet / Link
Architectural Patterns and Design Principles
• SPA with client‑side routing
• Component‑based hierarchy (pages, layouts, router components)
• File‑based routing convention (folder structure under src/pages)
• Plugin‑based build system (Vite plugins for React)
a. Developer Environment (left)
b. Build Pipeline (center)
c. Browser Runtime (right)
2. In “Developer Environment”:
• Block: Editor / File System → ESLint (optional)
3. In “Build Pipeline”:
• Blocks: TypeScript Compiler, React Plugin, Vite Bundler → Output assets (JS/CSS)
4. In “Browser Runtime”:
• index.html loads → main.tsx
• RouterProvider uses routeParser → renders Pages under src/pages
• Components: Link, Outlet for navigation