无法通过路径产品详细信息打开在 azure 中托管的角度应用程序

问题描述 投票:0回答:1

我有一个托管在 Azure 中的 Angular 应用程序。用户希望通过将特定网址粘贴到浏览器(https://somehosting.com/myapp/product/detail/123)来打开应用程序,但无法通过重定向到 https://somehosting.com 的方式打开应用程序 甚至不https://somehosting.com/myapp

如果我粘贴到浏览器中https://somehosting.com/myapp,它可以打开,但如果我粘贴带有产品 ID 的完整网址,则无法打开。 有人遇到过这样的问题吗?任何帮助将不胜感激

angular azure azure-devops angular-routing
1个回答
0
投票

过去我遇到过类似的问题。如果您使用 Azure Web 应用程序,我将使用 web.config 文件。这解决了我上次的问题。将此 web.config 文件添加到应用程序的根目录。这会将 IIS 的重写规则设置为“/”。

该配置应该如下所示

<?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="/nameOfApp/index.html" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

该网址应通过您的index.html 中的href 反映出来。确保您的index.html 中的标签设置正确。或者,如果您的应用程序托管在 /myapp 下,那么您应该将其设置为 .这可以确保 Angular 的路由器知道其所有路由的正确基本路径。

© www.soinside.com 2019 - 2024. All rights reserved.