项目原本是hash模式,只要将打包后的文件夹拷贝到webapps目录下就能访问,但是有些资源文件路径不正确(我的项目是微前端架构,将原来的相对路径改为绝对路径即可)
由于种种原因要换用BrowserHistory路由,按之前的方式部署,只能访问首页,使用其他路由一刷新就404了,原因是tomcat将我的路由当作文档路径,去webapps目录中找对应文件,结果失败;


解决方法:
1、删除webapps/ROOT 目录下的所有文件,将你打包好的文件copy过来;
2、然后在ROOT中新建WEB-INF文件夹,

WEB-INF文件夹中新建web.xml,添加如下代码:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<display-name>webapp</display-name>
<description>
webapp
</description>
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
</web-app>
3、如果你设置过conf/server.xml中的 <Context>,注释它。

4、至此完成了,重启tomcat。
网友评论