Search code examples
firebase-hostingnext.js

next.js with firebase hosting: how to create the 404.html file for firebase?


I am using next.js with Static HTML export, and i want to use firebase for hosting.

The problem is that firebase require a page in the root called 404.html for unknown routes.

Is there a way to generate such page using next.js? or maybe change the firebase hosting behavior?


Solution

  • Actually i found a solution, i added to the firebase.json a rewrite to the error page:

    "rewrites": [
      {
        "source": "**",
        "destination": "/_error/index.html"
      }
    ]
    

    now, only if the page is not found, firebase will serve the error page as explained here: https://firebase.google.com/docs/hosting/url-redirects-rewrites