Navigation

Host a Single-Page Application

On this page

  • Overview
  • Procedure
  • Upload Your Built Application to Realm
  • Configure Realm to Serve Your Application
  • Pull the Latest Version of Your App
  • Add Your Built Application Code
  • Configure Realm to Serve Your Application
  • Deploy the Updated Hosting Configuration

Many web applications built with modern frameworks, like React, Vue, and Angular, are single-page applications (SPAs) that dynamically handle routing and rendering client-side instead of fetching each rendered page from the server. You can use MongoDB Realm to host your SPA and serve it to clients.

To host your app, you need to specify that it's a SPA in Realm. By default, Realm handles requests for a given resource by returning the file hosted at the specified resource path or a 404 if no file matches the path. However, SPAs render in a single, specific HTML file so all requests should return that file regardless of the requested resource path.

This guide covers how you can configure Realm Hosting to redirect all resource requests to a single file to support the SPA pattern.

Note
404 Errors in Single-Page Apps

When single-page application hosting is enabled, Realm always returns an HTTP 200 response with the app root regardless of the requested route. This means that you cannot specify a custom 404 page for a SPA. Instead, you should include custom code in your application to handle invalid routes.

Give Feedback

On this page

  • Overview
  • Procedure
  • Upload Your Built Application to Realm
  • Configure Realm to Serve Your Application
  • Pull the Latest Version of Your App
  • Add Your Built Application Code
  • Configure Realm to Serve Your Application
  • Deploy the Updated Hosting Configuration