Intro
why after deploying my react app and if i reloading my app with /pages or with routes it breaks but if i click in link and goes to /pages it doesn't break. i have build my app with react, vite and pnpm. how to solve this.
When you click on a link to navigate to a route (e.g., /pages), everything works fine because the React Router handles the navigation within the single-page application (SPA). However, when you refresh the page or directly navigate to a route like /pages it breaks.
I understand you're looking for a simpler solution. Let's break it down into the most basic steps to make your React app (built with Vite and pnpm) work after deploying, specifically with routes like /pages working even when refreshing or directly accessing them.
The Issue
Works when clicking links: React Router handles routing client-side, and everything works fine. Breaks when refreshing or directly accessing routes: This happens because the server doesn't know how to handle routes that don't map to static files, so it returns a 404 error.