如何找出为什么在IIS上运行的Angular应用不允许路由/ URL的“在新选项卡中打开链接”?

时间:2019-06-26 15:23:54

标签: angular iis

这在angular开发服务器上有效,但是在IIS(10.0)上我能得到

  

404-找不到文件或目录。您正在寻找的资源   可能已被删除,更名或暂时被删除   不可用。

在Chrome上。当我单击链接时,它可以正常工作。在使用角度开发服务器时,我使用proxy.conf.json启用API调用。在IIS中,这些定义如下。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="ReverseProxyInboundRule3" stopProcessing="true">
                    <match url="(.*pn/api/.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="{C:1}://b-XXX:19100/{C:3}" logRewrittenUrl="true" />
                </rule>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*api/.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{CACHE_URL}" pattern="^(https?)://([^/]+).*(api/.*)" />
                    </conditions>
                    <action type="Rewrite" url="{C:1}://b-ZZZ:18221/{C:3}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
        <staticContent>
            <mimeMap fileExtension=".cmap" mimeType="text/plain" />
            <mimeMap fileExtension=".pdm" mimeType="text/plain" />
            <mimeMap fileExtension=".pdt" mimeType="text/plain" />
        </staticContent>
    </system.webServer>
</configuration>

我的index.html看起来像这样:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>YYY App</title>
  <base href="/yyyapp/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.0a90b702423cc0234e73.css"></head>
<body>
  <app-root>Loading...</app-root>
<script type="text/javascript" src="runtime.26209474bfa8dc87a77c.js"></script><script type="text/javascript" src="polyfills.a73720f7fce1093697ef.js"></script><script type="text/javascript" src="scripts.9142a59cca85c6bb7aa5.js"></script><script type="text/javascript" src="main.fc2905abff461388a63e.js"></script></body>
</html>

1 个答案:

答案 0 :(得分:1)

在服务器中添加 web.config 文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="AngularJS" 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="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>