【问题标题】:Angular url problems on IISIIS 上的 Angular url 问题
【发布时间】:2020-10-28 03:55:52
【问题描述】:

我将我的 dot net core 3.1 api 和 angular 9 应用程序部署到 IIS 中。 Api 运行良好。当我点击登录网址时,它运行良好并将我带入我的仪表板。 http://192.168.15.12:8020/ePortal/home.

之后,当我点击我的其他组件时说我想去颜色。当我点击颜色时,网址是 http://192.168.15.12:8020/home/color-details 而不是 http://192.168.15.12:8020/ePortal/home/color-details 这就是它显示 404(未找到)错误的原因。

我已经使用ng build --prod --base-href /ePortal/ 构建了产品,还添加了一个 web.config 来重写 url

<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="/ePortal/" />
        <!--<action type="Rewrite" url="/" /> /ePortal/-->
      </rule>
    </rules>
  </rewrite>
</system.webServer>
</configuration>

我无法确定问题所在。请帮忙

【问题讨论】:

    标签: angular angular-material angular-ui-router


    【解决方案1】:

    这是一个角度路由问题。您正在使用相对路径,但您需要为此使用绝对路径。尝试在您的路由器链接之前添加“/”。

    示例:使用 routerLink = "/color" 代替 routerLink = "color"

    更新

    使用这个

    <a mat-list-item href="color-details">Color</a>
    

    【讨论】:

    • &lt;a mat-list-item href="/home/color-details"&gt;Color&lt;/a&gt;我用过这个。
    • 当我点击颜色时,网址应该是http://192.168.15.12:8020/ePortal/home/color-details ,但它不是重写。它继续http://192.168.15.12:8020/home/color-details
    • 非常感谢。将是&lt;a mat-list-item href="home/color-details"&gt;Color&lt;/a&gt; 错误是由于 home 之前的 / 而发生的
    【解决方案2】:

    解决方案

    你不能将不同的路径目录重定向到角度,所以你需要为它添加自定义

    示例:

    <a href="home/color-details">Color</a>
    

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 1970-01-01
      • 2012-06-18
      • 2017-10-08
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多