angularjs - angularjs 默认页面,无需键入 index.html
问题描述
我正在使用 VS 2017 社区创建一个 angularjs 应用程序。当我在本地运行应用程序时,我会在地址栏中获得带有端口的 localhost,但默认情况下它不会带我进入 index.html。如果我在其中键入 index.html ,那么它可以工作,但是由于所有路由都通过连接在 index.html 中的 angular 应用程序,这会破坏路由。我无法输入 localhost:portnumber/my_other_route_here,因为它不会通过 index.html 中定义的 angularjs 应用程序。如何让 IISExpress 自动路由到 index.html 而无需键入 index.html?
我的配置文件中有以下内容,并认为它会对此有所帮助,并且过去有,所以不确定这次有什么不同。
<!-- Must have this so that direct entries in the browsers address bar get routed correctly. This routes entires that don't have physical paths to index.htm which
will route it correctly if a path is setup. Basically this allows for pretty url's like localhost:1234/red -->
<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="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
<!-- END rules -->
解决方案
所以我为 Web API(不是 MVC)使用了默认的 ASP.NET 应用程序模板,但它还是添加了 MVC。它有一个正在做一些映射的 RegisterRoutes() 的事实似乎就是发生这种情况的原因。当我在这里注释掉所有内容(可能会删除整个文件)时,默认情况下它会打开 index.html 而无需将其放在地址栏中。
推荐阅读
- microsoft-teams - 应用程序在 Teams 内运行,但不在本地主机上
- reactjs - 这个 React 代码中的“ref”做了什么
- html - 浏览器对@media 查询的解释存在错误
- scala - 为什么将具有 3 字段元组的普通 RDD 转换为 map 方法中的键值对是有效的?
- apache-spark - 提高窗口功能性能
- javascript - 对对象集合(不是数组)进行排序
- vue.js - 如何检测请求是否被 AdBlocker 阻止?
- python - 如何按日期过滤python pandas数据框列
- google-cloud-platform - GCP 列出项目中的所有内容
- java - URL请求在android Request.Method.POST中不起作用?