{"id":19867027,"url":"https://github.com/azurespheredev/vite-react-troubleshooting","last_synced_at":"2026-01-06T07:06:28.673Z","repository":{"id":259646476,"uuid":"823050545","full_name":"azurespheredev/vite-react-troubleshooting","owner":"azurespheredev","description":"My solution for resolving issues with react-router-dom in Vite + React project on production.","archived":false,"fork":false,"pushed_at":"2024-08-01T16:18:00.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T00:02:02.257Z","etag":null,"topics":["configuration","deployment","react","react-router-dom","troubleshooting","vercel","vite"],"latest_commit_sha":null,"homepage":"https://vite-react-boilerplate.vercel.app/solution","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azurespheredev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-02T10:28:04.000Z","updated_at":"2024-08-01T16:07:00.000Z","dependencies_parsed_at":"2024-10-27T04:39:53.266Z","dependency_job_id":null,"html_url":"https://github.com/azurespheredev/vite-react-troubleshooting","commit_stats":null,"previous_names":["blitzsprinter/vite-react-troubleshooting","azurespheredev/vite-react-troubleshooting"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azurespheredev%2Fvite-react-troubleshooting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azurespheredev%2Fvite-react-troubleshooting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azurespheredev%2Fvite-react-troubleshooting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azurespheredev%2Fvite-react-troubleshooting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azurespheredev","download_url":"https://codeload.github.com/azurespheredev/vite-react-troubleshooting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245579581,"owners_count":20638676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","deployment","react","react-router-dom","troubleshooting","vercel","vite"],"created_at":"2024-11-12T15:28:03.433Z","updated_at":"2026-01-06T07:06:28.626Z","avatar_url":"https://github.com/azurespheredev.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Fixing Routing on Vercel Deployment with Vite and React Router\n\nHere I've described how to address a common routing issue encountered when deploying a Vite + React application with React Router to Vercel.\n\n### The Problem\n\nSingle Page Applications (SPAs) handle routing on the client-side. When a user refreshes a specific route within the SPA, the server might not recognize that route and return a 404 error because there's no corresponding static file.\n\n### The Solution\n\nVercel is configured to handle SPAs by default. However, you can add a configuration file (`vercel.json`) to ensure proper routing behavior:\n\n1. **Create `vercel.json`:** In the project's root directory, create a file named `vercel.json`.\n\n2. **Add Rewrite Rule:** Paste the following code snippet into the `vercel.json` file:\n\n```json\n{\n  \"rewrites\": [\n    {\n      \"source\": \"/(.*)\",\n      \"destination\": \"/index.html\"\n    }\n  ]\n}\n```\n\nThis configuration tells Vercel to rewrite any incoming request path (`/.*`) to serve the `index.html` file. This React app will handle the routing based on the URL within the `index.html`.\n\n### Benefits\n\n- Prevents 404 errors on route refresh.\n- Improves user experience by ensuring secure navigation within our SPA.\n\n### Additional Notes\n\n- While Vercel handles routing by default, this configuration explicitly defines the behavior, making our deployment more robust.\n- Remember to commit the `vercel.json` file to our version control system for future deployments.\n\n### Resources\n\n- Vercel Documentation on Rewrites: [https://vercel.com/docs/edge-network/rewrites](https://vercel.com/docs/edge-network/rewrites)\n- React Router Documentation: [https://reacttraining.com/react-router](https://reacttraining.com/react-router)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazurespheredev%2Fvite-react-troubleshooting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazurespheredev%2Fvite-react-troubleshooting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazurespheredev%2Fvite-react-troubleshooting/lists"}