【问题标题】:Angular Routing - Have to use index.html first for route to workAngular Routing - 必须首先使用 index.html 才能工作
【发布时间】:2020-06-23 19:28:45
【问题描述】:

我是 Angular 的新手,并且已将应用程序部署在 wwwroot 文件夹之外的 IIS 10 上。 IIS 安装了 URL Rewrite,这是我正在使用的 web.config 文件的内容。

<?xml version="1.0" encoding="utf-8"?>
<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="./index.html" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

</configuration>

在 index.html 文件中我有&lt;base href="/"&gt;

当我构建应用程序时,这是我使用的命令:

ng build --base-href "/myapp" --prod

当我浏览到网站 https://servername/index.html 时,页面加载并且 URL 变为 https://servername/myapp/

如果我尝试直接访问 https://servername/myapp/,我会收到服务器 500 错误,除非我先使用 https://servername/index.html

我的最终目标是能够使用https://servername/myapp/?param1=123&param2=321 但是,这只有在我首先访问 https://servername/index.html 时才有效。

【问题讨论】:

    标签: angular iis-10


    【解决方案1】:

    原来是权限问题。我将以下代码添加到我的 web.config 文件中,它准确地告诉了我需要做什么来解决这个问题。

    <system.web> <customErrors mode="Off"/> </system.web>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      相关资源
      最近更新 更多