vue2.0構建項目,
默認不做配置,使用是hash模式,地址欄上有個“/#/”號,like http://localhost:8000/#/login 這樣.
官網文檔使用history模式可以去掉#,樣子like http://localhost:8000/login 這樣.
history模式下:
當項目,在nginx上運行頁面時,由於history模式的鏈接url是僞靜態 路由地址都是虛擬地址,
直接訪問找不到,會報404錯誤,需要rewrite url規則來支持。
方法一:在nginx上:修改nginx的配置文件,vim /usr/local/nginx/conf/nginx.conf
location / {
#......
#所要添加的配置代碼
try_files $uri $uri/ /index.html;
}
方法二:註釋掉history
export default new Router({
// mode: 'history',
routes: routes,
})
能力不足水平有限
有問題別講髒話罵人
來學習交流
有問必答
email:[email protected]