404 page displayed on laptop

How to handle a 404 in a Single Page Application deployed to Netlify?

Handling the HTTP 404 errors is important. Showing a page that is user friendly is a must in terms of UX. Without it, you may loose a customer.

Out of the box, Single Page Application (SPA) handle what we call soft 404. When you deploy to Netlify, we will see a page like this one:

Netlify 404 Not Found page

To avoid that, it is as simple as adding a _redirects file in the public directory of the application and adding the following:

1
/* /index.html 200

This lets the SPA handle the 404 as a soft 404.

See this forum thread for more usecases.

Credit: banner image by Erik Mclean on Unsplash

License GPLv3 | Terms
Built with Hugo
Theme Stack designed by Jimmy