Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix an error "CODE NOT FOUND" in Vercel?

Tags:

reactjs

vercel

I tried to deploy my app to Vercel (create-react-app starter). It was deploy successful, no errors in console or my vercel account. But when i clicked a link, i have this message:

404: NOT_FOUND Code: NOT_FOUND ID: ...

How to fix that? I have React (hooks, router) and Redux store, no database, no next.js. Thank you!

like image 790
Dmitriy Avatar asked Sep 02 '25 16:09

Dmitriy


1 Answers

i fixed this issue just now. turns out that only 1 route works, the "/" home route and other routes work for a short time, when you refresh the page, it shows a 404 page. it only happens if you don't configure your vercel.json. The routes don't get recognized except the "/" Home page route.

follow these steps:

  1. go to your project and add a vercel.json file. Then add these lines
{ "rewrites": [{ "source": "/(.*)", "destination": "/" }] }
  1. On the vercel deployment dashboard, pick vitejs as framework
  2. to learn more about this, head to their official documentation

I really hope it helps anyone on the internet

like image 133
JoyShaheb Avatar answered Sep 05 '25 08:09

JoyShaheb