Vue 项目部署到服务器后,刷新页面出现 404

新建 Vue 项目后,配置路由为 history 模式后,浏览器刷新后,显示404。

对于 URL:https://code.nanvon.cn/home,刷新后浏览器访问的是服务器中/home路径的位置,但是服务器中没有找到该路径,所以显示404,需要在nginx配置文件中加上如下代码:

location / {
		try_files $uri $uri/ @router;
		index index.html;
}
location @router {
		rewrite ^.*$ /index.html last;
} 
posted @ 2021-12-12 22:01  南枫Von  阅读(1597)  评论(0编辑  收藏  举报