0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Azure Static Web Apps] Vue.js history mode の 404対策

Last updated at Posted at 2020-12-19

Azure Static Web Apps にデプロイされたVue.jsコンテンツで
ページ遷移した際に、リロードすると404エラーになってしまう。
その対策について。

なぜ404になっちゃう?

実態ファイルのは無いので、404エラーとなってしまう

解決方法

Azure Static Web Apps のroutes設定によるリダイレクトで解決する。
(netlify だと _redirects ファイルによる設定)

public ディレクトリ直下に、routes.json を作成。
すべてのルートで/index.html が返されるように以下のよう記述

routes.json
{
  "routes": [
    {
      "route": "/*",
      "serve": "/index.html",
      "statusCode": 200
    }
  ]
}

この設定によって、ページのURLはそのままに
常に、index.html が返されるようになります。

関連URL

Azure Static Web Apps プレビューでのルート
https://docs.microsoft.com/ja-jp/azure/static-web-apps/routes

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?