DEV Community

Cover image for How to fix Error 404 on Netlify for SPAs built with Reactjs
Naftali Murgor
Naftali Murgor

Posted on

10 1

How to fix Error 404 on Netlify for SPAs built with Reactjs

Introduction

Hosting a React application on the Netlify platform often runs into an "Error 404". This is because an app built with Reactjs is a SPA (Single Page Application). Routing is done on the application and no HTTP calls are made to fetch pages server-side.

To fix this error,

  1. go to the public folder of your application
  2. create a file name _redirects( no file extension)
  3. add the following content to the _redirects file:
/*    /index.html   200
Enter fullscreen mode Exit fullscreen mode
  1. Rebuild the application and the error is fixed.

This tells Netlify to route all redirects to the index.html which is the root entry of your application. In Firebase hosting, this is usually handled inside a config file inside the project root.

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay