LoginSignup
9

More than 3 years have passed since last update.

【Firebase Hosting】SPAなサイトでPage Not foundとでた

Last updated at Posted at 2019-07-16

React.js(SPA)で構築したサイトをFirebase Hostingを用いてデプロイすると、
以下のように、404 Page Not Foundと表示された。

スクリーンショット 2019-07-16 13.37.12.png

firebase.jsonでのHostingの設定に問題があったらしい。

変更前

firebase.json
{
  "storage": {
    "rules": "storage.rules"
  },
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

変更後

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

これを追加した。

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

参照: 公式ドキュメント

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9