Firebase ReactJs routing issue - Page not found

使用 firebase hosting 來 host reactjs 既時候 出現了以下問題
當我直接在 browser 輸入 ReactJs 的 route 既時候 出現了

Page Not Found
This file does not exist and there was no index.html found in the current directory or 404.html in the root directory

Page not found
firebase page not found

解決方法: 我們只需要在 firebase.jsonhosting section 加上 rewrites 到 index.html 便可以了

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Hope you find it useful

Chi Yau
Chi Yau
Software Engineer

Interested on Learning new stuff and experience sharing