我开发了Angular 7应用程序。我想在普通 Windows 7 桌面(未安装 IIS)中托管。当我刷新页面/路线时,它说
"404 Not Found - The requested URL was not found on the server".
我不想使用“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。提前致谢
最佳答案
在index.html中:
<base href="/">
以及web.config中:
<action type="Rewrite" url="/" />
应该可以。
关于angular - 刷新页面时显示找不到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56490494/