vue.js的項目的訪問鏈接如何去掉 # 呢客燕?
步驟如下:
1. 在路由定義的腳本里添加mode: 'history'
const router =newVueRouter({mode:'history',? routes:[...]})
2.以上步驟還不夠闺鲸,因為頁面刷新會出現404錯誤澳骤,還需要配置服務器
Apache
RewriteEngineOnRewriteBase/RewriteRule^index\.html$ -[L]RewriteCond%{REQUEST_FILENAME}!-fRewriteCond%{REQUEST_FILENAME}!-dRewriteRule. /index.html[L]
nginx
location/ {try_files$uri$uri/ /index.html;}
注:本地測試環(huán)境運行npm run dev時是不用配置的醋闭,但部署到服務器上是需要的鲤看。