【问题标题】:Deploy Angular on Tomcat with redirect configuration使用重定向配置在 Tomcat 上部署 Angular
【发布时间】:2025-12-07 05:45:01
【问题描述】:

我想在 Tomcat 7 服务器上部署我的 Angular 5 应用程序,但是当我单击刷新按钮时出现重定向问题,我总是收到 404 错误。 在 Angular 网站上,我找到了 Apache:

RewriteEngine On
    # If an existing asset or directory is requested go to it as it is
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    RewriteRule ^ - [L]
    # If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

它适用于 Apache 服务器,但不适用于 Tomcat,Tomcat 是否有类似的配置? 谢谢

【问题讨论】:

  • 我在网站上使用 Angular。
  • this 可能会有所帮助

标签: angular tomcat deployment


【解决方案1】:

一种避免将其重定向到使用散列模式的解决方案:

RouterModule.forRoot(routes, {useHash: true})

另一种选择是编写一个专用的 Java servlet 来执行重定向。

【讨论】: