Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Redirect Works Locally but 404s on Vercel

I’m experiencing an issue with my React application deployed on Vercel. I have a route /property/:id that includes a button which, when clicked, should redirect to /profile/:id. This redirection works perfectly on my local development environment but fails when deployed to Vercel, showing a 404 response in the console(id is utilized by firebase further in profile/:id).

Strangely, the redirection works fine when I am on the root / directory and navigate to /profile/:id directly. It only seems to fail when trying to redirect from /property/:id to /profile/:id

error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

in console it shows response 404

>Solution :

Ensure your Vercel deployment is configured to redirect all non-static and non-API requests to the index.html file. This can usually be done by configuring a vercel.json file in your project root with rewrite rules:

{
  "rewrites": [
    { "source": "/(.*)", "destination": "/" }
  ]
}

Review your React Router configuration for dynamic routes and ensure it matches your intended URL structures. Also, review any server-side configurations (like vercel.json) to ensure they allow for dynamic routing.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading