项目部署后,刷新页面出现404错误,在本地运行则正常。

原因:项目的路由不是采用hash模式(访问路径中间加#),而是采用了history模式(/A/B)。因此,需要在 nginx.conf配置文件中,加上try_files配置即可,例如:
server{
listen 3000;
server_name localhost;
location / {
root /opt/project/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
本文讲述了项目部署后遇到404错误的解决方法,关键在于将history模式的路由配置到nginx的try_files中,以确保正确解析URL。
1306

被折叠的 条评论
为什么被折叠?



