A React+Vite Stack That Ships Frontends Before the Backend Exists
Server-level mock tooling that shows real HTTP traffic in DevTools removes the biggest friction in frontend-backend parallel work. A team can ship a fully interactive UI, validate state management and routing, and merge to real endpoints later by toggling one config boolean — no dead-data cleanup, no last-minute rewiring.
Frontend teams routinely stall waiting for backend APIs. A standard React 18 + Vite stack eliminates that dependency by combining Axios API layering, server-level mock interception via vite-plugin-mock, and Zustand for global state. The mock plugin operates inside Vite’s Node dev server, so requests appear in the Network tab exactly like real calls — unlike browser-side Mock.js, which hides them.
The workflow is straightforward: wrap Axios with a shared baseURL and timeout, organize API functions by business module, then define mock arrays that match those exact URL paths. Flipping a single `enable` flag in vite.config.js switches the entire app from mock data to live backend endpoints with no code changes.
Routing gets a pragmatic treatment too. HashRouter deploys anywhere without server config and never 404s on refresh; BrowserRouter gives clean URLs but demands Nginx `try_files` or equivalent. Zustand replaces the Context+useReducer combo for global state, subscribing components only to the slices they consume and avoiding the re-render tax of Provider trees.
The mock-at-dev-server pattern (vite-plugin-mock) is a distinct upgrade over browser-side interception: it keeps the Network tab honest, which matters more for debugging velocity than most teams admit.
The architecture’s real payoff is the one-config switch from mock to production. That single boolean eliminates an entire class of integration bugs caused by manually replacing stubbed data across components.
Zustand’s selector-based subscriptions solve the Context performance problem without introducing the ceremony of Redux. For global state in React, the Context+useReducer pattern is now a legacy fallback, not a default.
HashRouter remains underrated in professional circles. For any app served from a CDN or static host without server config access, it is the only routing mode that won’t break on refresh.