0
点赞
收藏
分享

微信扫一扫

Nginx/Vue 远程服务部署项目,解决刷新浏览器报404错误

_鱼与渔_ 2022-12-31 阅读 96

解决 nginx 发布项目 刷新 404 问题。

 第一种解决办法:只需要在 nginx 中配置一段就代码就好了 

cd nginx/conf/

vim nginx.conf

# 在location / 中添加

try_files $url $url/ /index.html;

# 字面意思是如果当前路由404的情况下,试着进入当前路径的index.html

Nginx/Vue 远程服务部署项目,解决刷新浏览器报404错误_nginx

第二种解决办法:如果上面的办法仍没能解决,可以将路由模式改成hash模式,history还得做另外配置:

const router = new VueRouter({
// 路由模式:hash(默认),history模式
// mode: "history", // 这里地址: 127.0.0.1:8080/
mode: "hash", // 这里地址: 127.0.0.1:8080/#/
base: process.env.BASE_URL,
routes:customRoutes
});

将mode改为hash,但是这样路由会出现多一个#号。

 

举报

相关推荐

0 条评论