Skip to content

访问报404问题

我们项目弄好后要打包到服务器上,一般来说都是直接将dist文件夹丢上去到nginx,然后打开www.xxx.com,这时没问题,但是打开www.xxx.com/list刷新时,就会报404的情况。

解决方法

1.将history模式改成hash模式

2.配置nginx

location / {
 try_files $uri $uri/ @rewrites;
 index index.html;
}
 
location @rewrites {
  rewrite ^.*$ /index.html last;
}
location / {
 try_files $uri $uri/ @rewrites;
 index index.html;
}
 
location @rewrites {
  rewrite ^.*$ /index.html last;
}

程序员小洛文档