Use a Custom 404 Page¶
Overview¶
You can replace the default 404 page that MongoDB Realm displays when a user tries to
access a resource that does not exist with a custom HTML document. You
can specify this custom 404 page from the Realm UI or by importing an application configuration
directory that includes the page in its hosting
directory. Select
the tab below that corresponds to the method you want to use.
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.
Procedure¶
Create a Custom 404 Page File¶
You can use any hosted file as your custom 404 page. It's common to use an HTML file that incorporates the following elements:
- A short message indicating the error, e.g. "This page does not exist."
- Alternative links or options for the user to continue navigating.
Host the 404 File in Realm¶
Once you've created the custom 404 file, you need to upload it to MongoDB Realm. To upload the file, navigate to the Hosting screen of the Realm UI, click Upload Files, and select the custom HTML file.
Configure the 404 Resource Path in Realm¶
Once you have successfully uploaded the 404 file, all that's left is to configure Realm to serve that file instead of the default 404 page.
- On the Hosting page, click the Settings tab.
- Under Custom 404 Page, click Choose File.
- Select your custom 404 file from the list.
- Click Save.
Once you have updated the Hosting configuration, Realm will begin serving your custom file instead of the default 404 page.