Vue プロジェクトを更新すると 404 問題が発生する

vue ページへのアクセスは正常ですが、更新されるとすぐに 404 問題が発生します。解決策は 2 つあります。

1. vue ルーティング モードをモード: 'history' からモード: 'hash' に変更します。

        ルーティングに使用される js ファイルのモード値を変更するだけです。たとえば、私の js ファイルは次のようになります。

        

//index.js文件
const router = new Router({
    //mode: 'history', 
    mode: 'hash',
    routes: [
        { path: '/', redirect: '/login' },
        { path: '/login', component: Login },
    ]
})

2. サーバーNginx構成ファイルに次のコードを追加し、再度更新します。

location / {
 try_files $uri $uri/ @router;
  index index.html;
}
 
location @router {
  rewrite ^.*$ /index.html last;
}

おすすめ

転載: blog.csdn.net/weixin_47406082/article/details/132613033
おすすめ