场景:最近接触了一个vue的项目,打包之后部署到阿里云服务器上之后,点击连接一级一级进页面没有问题,但是刷新页面就出现404,找了两个解决方法,供大家一起学习。(本人模拟了在nginx和tomcat的解决方法)
1,项目打包的时候index.js修改assetsPublicPath: ‘/’
2.如果部署在tomcat上:在tomcat的webapps下的项目中创建WEB-INF文件夹,在文件夹中创建文件web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
<display-name>Router for Tomcat</display-name>
<error-page>
<error-code>404</error-code>
<location>/index.html</location>
</error-page>
</web-app>
3,如果部署在nginx上:修改nginx的配置文件,xx为项目存放的文件夹