【问题标题】:Page not found displays when I refresh a page刷新页面时显示找不到页面
【发布时间】:2019-06-07 08:16:24
【问题描述】:

我开发了 Angular 7 应用程序。我想在普通 Windows 7 桌面上托管(它没有安装 IIS)。当我刷新页面/路线时,它在说

“404 未找到 - 在服务器上未找到请求的 URL”。

我不想使用 “HashLocationStrategy”

我尝试如下创建 web.config 并添加到项目文件夹中

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="AngularJS" 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="http://localhost/sp/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

在上面的代码中,我尝试将 Rewrite URL 保留为“/”,但没有帮助 我仍然遇到同样的错误。

我的 index.html 页面

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Title</title>

  <base href="./" />

  <meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="msapplication-tap-highlight" content="no" />

  <link rel="icon" type="image/png" href="assets/icon/favicon.png" />

  <!-- add to homescreen for ios -->
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" href="styles.30b5b974b5c7cd59b7d1.css"></head>

<body>
  <app-root></app-root>
<script type="text/javascript" src="runtime.2ec62019cc97e19fb61f.js"></script><script type="text/javascript" src="polyfills.b7025f5354b70ae0544f.js"></script><script type="text/javascript" src="scripts.ccb1b8327b72db7af87a.js"></script><script type="text/javascript" src="main.1d9ddad52d76d8c93cdd.js"></script></body>

</html>

我除了刷新后页面会重新加载,但我收到 404 错误

您能帮我解决问题/如何配置 web.config。提前致谢

【问题讨论】:

    标签: angular windows


    【解决方案1】:

    index.html 中:

    <base href="/">
    

    web.config 中:

     <action type="Rewrite" url="/" />
    

    应该可以。

    【讨论】:

    • 进行了上述更改,但仍然无法正常工作。在原帖中添加了截图。
    猜你喜欢
    • 2021-08-15
    • 1970-01-01
    • 2012-12-19
    • 2019-02-11
    • 2021-07-20
    • 2019-12-24
    • 2020-01-06
    • 1970-01-01
    • 2020-09-22
    相关资源
    最近更新 更多