LoginSignup
1
0

More than 3 years have passed since last update.

【Nuxt.js】生成するHTMLを1つだけにする方法【SPA】

Posted at

やりたいこと

vue.jsと同じ用に1つだけhtmlを生成するようにしたい。

nuxt.config.jsの設定

nuxt.config.jsに以下の変更を加える事でルーティングのhtmlが生成されなくなる。
ルーティングのhtmlの1つも生成されない場合は200.htmlが生成される。
参考:https://ja.nuxtjs.org/docs/2.x/configuration-glossary/configuration-generate/#exclude

nuxt.confing.js
export default {
  generate: {
    exclude: [/.*/]
  }
}

サーバ側の設定

リダイレクトの設定を行う。

Apacheの場合

.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ 200.html
</IfModule>

参考:https://router.vuejs.org/ja/guide/essentials/history-mode.html#サーバーの設定例

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