首页 > 解决方案 > Angular 7 组件。404 - 找不到文件或目录

问题描述

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

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

标签: angularroutescomponentsrouter

解决方案


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

推荐阅读