作为战争部署在 tomcat 上的 Angular 应用程序 [英] Angular App deployed on tomcat as war

查看:35
本文介绍了作为战争部署在 tomcat 上的 Angular 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想部署一个用 Angular 编写的单页应用程序 (SPA) 和一堆静态文件,包括 *.css、.js、/assets/ 在 tomcat 上的 war 文件中.

I'd like to deploy a single page application (SPA) written in Angular with a bunch of static files, including *.css, .js, /assets/ within a war file on tomcat.

问题是,用户给出的每一个与现有文件不匹配的路径都应该提供 index.html.

The problem is, every path given by the user which doesn't match one of the existing files should deliver index.html.

我从这个 web.xml 配置开始:

I started with this web.xml configuration:

[...]
  <servlet>
    <servlet-name>index</servlet-name>
    <jsp-file>/index.html</jsp-file>
  </servlet>
  <servlet-mapping>
    <servlet-name>index</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
  [...]

不幸的是,这个索引也匹配现有的静态文件.

Unfortunately this index also matches existing, static files.

你知道如何解决这个问题吗?

Do you have any idea how to solve this?

推荐答案

每个与任何文件不匹配的路径都会传递 404 错误代码

Every path which doesn't match any file delivers a 404 error code

工作 web.xml:

Working web.xml:

[...]
<error-page>
    <error-code>404</error-code>
    <location>/index.html</location>
</error-page>
[...]

在每个未找到的页面上,它将重定向到 index.html

On every not found page it will redirect to index.html

这篇关于作为战争部署在 tomcat 上的 Angular 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆