配置nginx解决vue路由history模式下刷新404问题

配置nginx解决vue路由history模式下刷新404问题

在 vue 路由模式为 history 的时候,刷新页面会出现 404 问题。我们只需要在服务器配置如果 URL 匹配不到任何静态资源,就跳转到默认的 index.html。

1
2
3
4
5
6
7
8
9

server {
listen 8105; // 表示你nginx监听的端口号
root /home/admin/sites/vue-nginx/dist; // vue打包后的文件夹dist目录
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
#

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×