刷新页面时显示未找到页面

时间:2019-06-07 08:16:24

标签: angular windows

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

  

“找不到404-在服务器上找不到请求的URL”。   enter image description here

我不想使用“ 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>

在上面的代码中,我尝试将重写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。预先感谢

1 个答案:

答案 0 :(得分:2)

index.html 中:

<base href="/">

web.config 中:

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

应该工作。

相关问题