VUE项目打包后使用Tomcat部署 解决页面刷新后404问题

277 阅读1分钟

解决办法
在ROOT目录下,新建一个WEB-INF文件夹
在这里插入图片描述
cd到文件夹中,编辑一个web.xml文件
在这里插入图片描述
文件具体内容如下,大概意思是,当页面404时回到首页

<?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>