Angular App deployed on tomcat as war

删除回忆录丶 提交于 2019-12-24 02:14:19

问题


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.

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

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?


回答1:


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

Working web.xml:

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

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



来源:https://stackoverflow.com/questions/50346429/angular-app-deployed-on-tomcat-as-war

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!