使用IIS URL重新写入时,Angular应用程序未使用参数加载 [英] Angular application not loading with parameters when reloading with IIS URL Rewrite
问题描述
我在本地IIS中配置了Angular 8应用程序.我还安装并配置了IIS URL Rewrite.问题是,如果我从起始页访问该应用程序,则该应用程序将正常加载.但是,无论如何,如果我重新加载应用程序,或者尝试使用URL访问内部页面,都会收到以下错误.
I have an Angular 8 application configured in my local IIS. I have also installed and configured IIS URL Rewrite. The issue is that the application is loading fine if I access it from the start page. But if at any instance, I reload the application or if I try to access the inner pages using the URL, I get the following error.
请在下面找到我的IIS URL重写配置:
Please find my IIS URL Rewrite config below :
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/$" negate="true"/>
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这是index.html:
This is the index.html :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Business Continuity Planning Tool</title>
<base href="./" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link rel="stylesheet" href="styles.6d575a836e8b4e63af3b.css"></head>
<body>
<app-root></app-root>
<script src="runtime-es2015.d3bc0f0c5758d81e0404.js" type="module"></script><script src="polyfills-es2015.f2e75f3c844d6aea9986.js" type="module"></script><script src="runtime-es5.1b294c6bb1a350f5c4a5.js" nomodule></script><script src="polyfills-es5.c56107a30ff96141ff8f.js" nomodule></script><script src="scripts.e84dbffa93eee937834f.js"></script><script src="main-es2015.b4de925263cc98440efd.js" type="module"></script><script src="main-es5.cb2c1b5748b9aef1ff23.js" nomodule></script></body>
</html>
如果我从没有任何URL参数的主页访问该应用程序,则其工作正常.仅在有参数的内页中出现此问题.由于没有参数,因此重新加载也可在主页上进行.
If I access the application from the home page which doesn't have any URL parameters, its working fine. The issue comes up only in the inner pages where there is a parameter. The reload also works on homepage as there are no parameters.
主页URL: http://localhost:81/BcpApp/home ,
内页网址: http://localhost:81/BcpApp/editbcp/5016
我坚信问题出在IIS URL重写配置上,因为当我使用节点运行应用程序时这些问题不存在.
I strongly believe that the issue is on the IIS URL rewrite configuration as these issues are not present when I am running the application using node.
推荐答案
<base>
标签很重要.它显示了应用程序的开始" URL部分在哪里.
尝试将基准渲染为<base href="/BcpApp/" />
.这将使<script src="/scripts/myscript.js">
之类的所有调用以及角度路由都以'/BcpApp/'url部分为前缀
<base>
tag is important. It shows where is the "start" url part of your application.
try rendering base as <base href="/BcpApp/" />
. this will make all calls like <script src="/scripts/myscript.js">
as well as angular routing to be prepended with '/BcpApp/' url part
这篇关于使用IIS URL重新写入时,Angular应用程序未使用参数加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!