问题
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