Skip to content

Light version: pages open quickly, without the 3D graphics. You are seeing the light version because the 3D graphics would be slow on this device. The content is the same.

Turn on 3D

Preparing the graphics. This can take a moment on the first visit.

Henry Lõiv

Web design & development

Quick Answer

Why does my Vue or React app return 404 on refresh?

Development 2 min read

A common cause is a missing hosting fallback for client-side routes. Clicking inside the app lets the browser’s router choose the view. Refreshing /projects/example asks the server for that address directly, and a static host may look for a file that does not exist. 12

Confirm which request fails

Open a valid nested route through the menu, then refresh it with the browser’s Network panel open. Inspect the document request, not just the console. Compare that result with opening the same URL in a new tab.

If the document returns 404 before the app loads, investigate hosting rules. If the document loads successfully but a JavaScript file fails, record that asset’s URL instead. These are different failures and should not receive the same blanket fix.

Serve the app for valid application routes

A static SPA host needs to serve the client entry page for application URLs. React Router’s deployment guide identifies missing host configuration as a likely cause of 404s on valid routes. 2

For nginx, Vue Router documents this fallback: 1

location / {
    try_files $uri $uri/ /index.html;
}

Adapt it to the deployment. Keep API requests and asset handling in their appropriate locations. If the app lives under a subdirectory, check its router base and deployed paths as well. Test a nested route, a real asset and an API endpoint after changing the rule.

Preserve missing-page behavior

A catch-all can make nonexistent URLs return HTTP 200. Showing a client-side “not found” component does not automatically change that server response. For public pages, return a genuine 404 where the architecture supports it, or apply an appropriate SPA error-page strategy. 13

This advice concerns static client-rendered apps. A server-rendered deployment needs its framework’s server routing; replacing that with a blanket index.html rewrite can hide the actual configuration problem.

Related reading

Sources

  1. Vue Router: Different history modes
  2. React Router: Single Page App deployment
  3. Google Search Central: JavaScript SEO basics and soft 404 errors

Fact checked:

Hi!

I really love the sea, yachts, sunsets and starry skies.

Through this little 3D world, I can share a small part of myself with you.

Thank you for opening this bottle and reading my letter.

Henry

Let’s talk about your project

Tell me about your project

Tell me what you’d like to build or improve. You don’t need a finished brief — we’ll work out the scope and next steps together.

01 How can I help?
02 How many pages do you need?
03 Which extras do you need? Choose all that apply
04 When does it need to be ready?
05 Project details
06 Your contact details

Enquiry received

Thank you!

Your enquiry has been received. I usually reply by email within 2 working days.