Angular 7组件。 404 - 找不到文件或目录

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

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

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

angular routes components router
1个回答
0
投票

我能够解决它,我需要将以下内容添加到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>
© www.soinside.com 2019 - 2024. All rights reserved.