Join our Newsletter — 33% off our NHI Course
Home FAQ Cyber Security Why do React router paths break on refresh…
Cyber Security

Why do React router paths break on refresh when a single-page app is served from a Go backend?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated September 15, 2026 Domain: Cyber Security

Refresh fails because the browser asks the server for the literal path, such as /about, instead of letting React Router handle client-side navigation. If the backend only serves static files that map to real paths on disk, that route will not exist. The fix is to fall back to index.html so the SPA can rebuild the route in the browser.

Why This Matters for Security Teams

A browser refresh changes the request path from internal client-side navigation into a direct server request. That means a route like /about is no longer a React Router concern, it becomes a backend routing problem. In a Go-served SPA, the failure usually appears as a 404 or a blank page because the server only knows about real files and API endpoints, not browser-managed routes.

For security teams, this matters because the fix is not just about user experience, it is about preserving the intended trust boundary between client routing and server routing. If the backend is misconfigured, operators may incorrectly diagnose an application bug, a reverse proxy issue, or a deployment regression when the real problem is that the server is not returning the SPA entry point for non-asset paths. When that fallback is missing, every deep link becomes brittle.

Ultimate Guide to NHIs is useful here as a reminder that resilient systems depend on clear ownership of the control plane versus the execution path, even when the application itself is not identity-centric. In practice, many teams only discover this routing gap after production users hit a bookmarked URL or a refreshed page, not during the initial happy-path testing.

How It Works in Practice

A single-page app handles navigation in the browser after the initial HTML loads. React Router updates the visible route without asking the server for a new page. On refresh, however, the browser issues an HTTP request for the current path exactly as shown in the address bar. If Go is serving static assets, it will try to resolve that path as a file or directory. Unless the path maps to an actual object on disk, the request fails.

The standard fix is to configure the Go backend, or the surrounding reverse proxy, to return index.html for all non-file routes that belong to the SPA. That lets the browser receive the app shell first, after which React Router can interpret the URL and render the correct view. The important distinction is that asset requests and API routes must still be served normally, while application routes need a fallback behavior.

  • Serve real static assets such as JavaScript, CSS, images, and favicon files directly.
  • Return index.html for client-side routes that do not match an existing file.
  • Keep API endpoints separate so fallback routing does not swallow legitimate backend requests.
  • Make sure 404 handling distinguishes missing assets from valid SPA paths.

In Go, this is often implemented with a file server wrapper, a route check, or middleware that inspects the request path before deciding whether to serve a file or the SPA entry point. The exact mechanism varies by framework and deployment topology, but the operational requirement is the same: the server must not treat browser routes as if they were filesystem paths. These controls tend to break down when API routes, static assets, and SPA routes share overlapping prefixes without explicit routing precedence.

Common Variations and Edge Cases

Tighter routing rules often increase configuration complexity, requiring teams to balance clean fallback behavior against the risk of accidentally masking legitimate backend errors. The details change depending on whether the app uses hash routing, history API routing, a CDN, or a reverse proxy in front of Go.

Hash routing avoids server-side fallback entirely because the browser fragment never becomes part of the HTTP request, but it produces less clean URLs and is often a poor fit for modern applications. History API routing gives better URLs and user experience, but it makes the backend responsible for serving the SPA shell correctly. In production, edge caching layers and ingress controllers can also interfere if they rewrite paths or intercept 404 responses before the Go handler sees them.

One common mistake is to fix refresh failures by broadening the fallback too aggressively. That can hide genuine errors, break API diagnostics, or cause every unknown path to return a successful page, which makes troubleshooting harder. The right pattern is precise matching: static files and real backend routes should continue to behave normally, while only SPA navigation paths resolve to the app entry point. For teams that need a broader identity and lifecycle view of route ownership, Ultimate Guide to NHIs, Lifecycle Processes for Managing NHIs is a useful reference point for how disciplined control boundaries prevent operational ambiguity.

Risk and Threat Considerations

The primary risk is availability and integrity of application navigation, not confidentiality. When SPA fallback is missing or misrouted, users lose access to bookmarked pages, deep links, and refreshed views, which can look like intermittent application failure even though the frontend code is fine. The larger operational risk is that teams may patch symptoms in the client while the real fault remains in server routing.

Failure mechanism: The browser sends a direct request for the current path, the Go backend interprets that path as a filesystem or backend route, and the request fails when no matching resource exists. In deployments with proxies or CDNs, an overbroad rewrite or error-handling rule can also hide the real routing problem and make diagnosis slower.

Impact: Users encounter 404s, blank screens, or route-dependent outages, and support teams may lose confidence in the deployment pipeline because the application works on first load but fails on refresh or direct entry.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

CIS Controls v8 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
CIS Controls v8CIS 4 — Secure Configuration of Enterprise Assets and SoftwareSPA fallback behavior depends on correct server and proxy configuration.
Recommendation — Harden the Go server and proxy route handling so client routes fall back only where intended.
NIST CSF 2.0PR.PT — Protective TechnologyThe issue is a deployment control problem affecting application availability and correct routing.
Recommendation — Implement protective routing controls that preserve SPA navigation without breaking backend paths.

Practitioner Guidance

What to verify: Confirm that the Go server returns index.html for client-side routes but still serves real assets and API endpoints normally. Test a refreshed deep link, a bookmarked URL, and a missing static file separately, because those three cases should not behave the same way.

Decision rule: If a path is meant to be handled by React Router, the server should hand back the SPA shell; if it is a real asset or API route, it should not. That distinction should be explicit in code or in the reverse proxy, not left to default file-server behavior.

Common mistake: Do not use a catch-all rewrite so broad that it turns every unknown request into a success response. That makes debugging harder and can conceal genuine backend problems behind a working frontend shell.

Practitioner takeaway: The stable pattern is to let the browser own navigation after load, while the backend owns only the initial shell, assets, and APIs, with no ambiguity about which layer answers which path.

Deepen Your Knowledge

Sign up to our weekly newsletter — get 33% off our NHI Foundation Level Course

    NHIMG Editorial Note
    Reviewed and updated by the NHIMG editorial team on September 15, 2026.
    NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org