使用 vue 寫的程序,在瀏覽器中看到的路由都是帶有#的拾碌,很是不好看吐葱。
為了解決此問題,大家一般都會采用:mode: 'history'校翔,在開發(fā)階段沒有問題弟跑,
但是build打包后,訪問并刷新瀏覽器后防症,頁面就會報404的錯誤孟辑,
為了解決打包后刷新瀏覽器報404的問題,如果使用nginx的話蔫敲,需要做如下配置:
1饲嗽、路由代碼中添加mode:'history'
2、nginx配置
? ? ?在nginx的配置文件中添加:try_files $uri $uri/ /index.html;
location / {
? ? ? ? root /Users/libo/Documents/workspace/Vue-me/my-project/dist;? ? ? ?
? ? ? ? index index.html index.htm index.php;
? ? ? ? try_files $uri $uri/ /index.html;? ??
}