【问题标题】:Angular 7 component. 404 - File or directory not foundAngular 7 组件。 404 - 找不到文件或目录
【发布时间】:2019-07-18 20:36:41
【问题描述】:

我有一个名为 r 的组件,它通过查询字符串接收一个名为 a 的参数。当我从 VS Code 尝试它时,它工作得很好。 后来我使用 Windows 和 IIS 在我的服务器上发布它并打开页面https://mypage/r?A= Fl,浏览器返回 404 - 找不到文件或目录。但是 R 分量是存在的。

你怎么能解决这个问题?感谢您的帮助。

【问题讨论】:

  • 您是否尝试过构建您的应用程序?阅读Deployment
  • 是的,我执行的命令是:ng build --outputPath = dist / --prod = true

标签: angular routes components router


【解决方案1】:

我能够解决它,我需要将以下内容添加到 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>

【讨论】:

  • 好你想通了。我希望文档对您有所帮助。 :)
猜你喜欢
  • 1970-01-01
  • 2020-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-28
  • 2023-04-11
  • 2019-10-15
  • 2021-01-31
相关资源
最近更新 更多