解决 nginx 发布项目 刷新 404 问题。
第一种解决办法:只需要在 nginx 中配置一段就代码就好了
cd nginx/conf/
vim nginx.conf
# 在location / 中添加
try_files $url $url/ /index.html;
# 字面意思是如果当前路由404的情况下,试着进入当前路径的index.html
第二种解决办法:如果上面的办法仍没能解决,可以将路由模式改成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,但是这样路由会出现多一个#号。