IBM WebSphere部署Angular 5应用程序并在刷新时获得404

时间:2018-04-25 23:32:47

标签: java linux angular unix websphere

我使用Angular(当前版本为5)构建完整堆栈应用程序通常后端为Windows Server并且它使用IIS,因此我知道使用重写模块代码部署web.config文件。

问题是网站是SPA,无论网址是什么,它都需要始终指向index.html。

正如我所说,我已经习惯了Windows,但后端是Java IBM Websphere

任何人都知道我需要做些什么来正确使用Angular应用程序?

示例,WINDOWS的配置是如下所示的web.config,但这是带有Java应用程序的Websphere,我假设后端是Linux/unix

<configuration>
<system.webServer>
  <rewrite>
    <rules>
      <rule name="Angular Routes" stopProcessing="true">
        <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      </conditions>
      <action type="Rewrite" url="/MyApp/" />
      <!--<action type="Rewrite" url="/" />-->
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

1 个答案:

答案 0 :(得分:3)

您需要将以下内容添加到web.xml中,该文件打包在应用的.war文件中的WEB_INF目录中:

<error-page>
    <error-code>404</error-code>
    <location>/</location>
</error-page>

它告诉应用服务器在发出404错误时在应用程序的上下文根目录中显示资源。

相关问题