VUEに履歴モード、非ルートのエラーメッセージ404をルーティングします

ソリューション

找到src/router/index.js 文件添加代码
export default new Router({
  mode: 'history', //修改部分
  base: '/dist',  //修改部分 如果你的次级文件夹名是dist 这里就配置dist
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/test.html',
      name: 'Hello',
      component: Hello
    }
  ]
})

あなたはApacheサーバの場合は、httpd.confの設定ファイルのLoadModule rewrite_moduleモジュール/ mod_rewrite.soのコード行は、「#」記号を保存する削除は、Apacheを再起動して見つけます

その後、エラーをテストする方法の公式サイトに次のコードを追加し、新たな.htaccessファイルの下のフォルダDIST

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /dist/index.html [L]  //注意这个

あなたは、ルートディレクトリサーバにある場合はnginxの

location / {
  try_files $uri $uri/ /index.html;
}

ないルートディレクトリの下

location /your_router {
  try_files $uri $uri/ /your_router/index.html;
}
リリース7件のオリジナルの記事 ウォンの賞賛0 ビュー103

おすすめ

転載: blog.csdn.net/chenyu00544/article/details/104834724