HACKER Q&A
📣 thepra

Should a web app(PWA) redirect to a 404 page on route not found?


Given that the desktop like apps don't have a concept of "404 page not found" I was wondering if it's a welcome practice to have web apps redirecting to some other page locally like the root "/" of the app instead of showing 404 page?


  👤 _b0ns Accepted Answer ✓
All opinion-based, take with a grain of salt:

The numeric status code itself (404) is mostly for machine understanding purposes; the fact that many websites still render the number itself on the page is a strange quirk of the way that the web (and web servers, and online culture) developed.

It's fine for a PWA to use an HTTP 404 code locally -- for example for a service worker to return that status code when a URL is known not to exist either online or offline. You probably wouldn't want an HTTP 404 'locally' for something that 'could' exist if the user was online, because you don't want to cache the apparent non-existence of that content.

And then to the human/user side of the HTTP 404: it makes sense to display a relevant message to indicate to the person that the content was not found. That could be a generic "oh, we couldn't find what you were looking for" (localized), or it could be more context-sensitive -- "that conversation thread couldn't be found", for example.