angular - 多个 SPA 的 IIS 重写规则
问题描述
我们正在为我们的微前端创建一个新架构,并且我们希望避免使用另一个框架来处理它,比如single-spa。我们公司目前将 IIS 用于其他产品,我们需要保持这种方式。
因此,为了让多个 SPA 响应同一个地址,我们只需将我们构建的 SPA 放在 IIS 的内容目录中,如下所示:
IIS 根文件夹:
- 温泉1
- 温泉2
我可以正常访问myhost/spa1
并myhost/spa2
浏览他们自己的内部路线(我们使用的是 Angular)。
问题是,我们希望 URL 没有#
,并且我们需要告诉 IIS 将任何子路由重定向到它的 SPA 主路由。
我们有一些东西,它适用于myhost/spa1
, myhost/spa1/detail
,但不适用于myhost/spa1/detail/1
。比方说,第三级。
有人可以帮我解决这个问题吗?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SPA Rule" 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="{R:1}/" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
解决方案
尝试使用此 URL 重写规则:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="SPA Rule" 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="{R:1}/{R:2}" />
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
推荐阅读
- python - 在列表中查找单词,然后删除该单词和列中的任何其他尾随单词
- python - 获取csv内两列内的出现次数
- couchdb - 如何在重新启动超级账本作曲家休息服务器或作曲家游乐场时保留数据
- visual-studio-2017 - 如何处理 Odata?
- javascript - 如何处理 ES6 Promises 中的错误状态?
- php - PHP 7.2 均已弃用。将每个转换为 foreach
- typescript - 在编译输出中包含外部类型定义
- python - 如何在 TensorFlow 中获取张量的值(无需进行另一个会话)
- android - 房间 | 无法全部插入
- javascript - 无法读取 NodeJS 中未定义的属性“get”