问题描述:
一、更新依赖,并打包项目
cd /root/.jenkins/workspace/v-test;npm install
cd /root/.jenkins/workspace/v-test;npm run build
二、发布Tomcat
mv ../dist/* $tomcatpath/webapps/ROOT
三、第一次访问请求正常,刷新页面报404错误
怎么解决:
如果 URL 匹配不到任何静态资源,则应该返回同一个 app 依赖的index.html 页面。
在ROOT根目录下创建WEB-INF文件夹,在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>
这样一旦在出现404报错就返回到 index.html 页面。