Search code examples
create-react-appvercel

Why does Create React App hosted on ZEIT Now not show a 404 response?


If I try mywebsite.com/NON-EXISTENT-PATH for my site on Google App Engine, I get a 404 response.

However using create-react-app's local development server for another app, if I try localhost:3000/NON-EXISTENT-PATH, it just gives me the response for localhost:3000, rather than a 404. This also applies to hosting the app on ZEIT Now. Why is this?


Solution

  • Create React App is auto-detected and a wildcard route is added so that any path that doesn’t match a static file will serve /index.html.

    https://zeit.co/docs/v2/build-step#optimized-frameworks

    This is necessary for frameworks that don't create HTML files for each page but instead create a single index.html file and use JavaScript to route on the frontend.

    This pattern is typically called SPA.