angularjs默认页面,无需键入index.html

时间:2019-02-04 20:58:57

标签: angularjs visual-studio-2017

我正在使用VS 2017社区创建一个angularjs应用。当我在本地运行该应用程序时,我在地址栏中获得了带有端口的localhost,但默认情况下它不会带我到index.html。如果我在其中输入index.html,那么它可以工作,但是由于所有路由都经过与index.html连接的有角度的应用程序,因此会破坏路由。我无法在此处输入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 -->

1 个答案:

答案 0 :(得分:0)

因此,我将默认的ASP.NET应用程序模板用于Web API(不是MVC),但无论如何它都会添加MVC。它有一个RegisterRoutes()正在做一些映射的事实似乎就是为什么这种情况发生的原因。当我注释掉此处的所有内容(可能会删除整个文件)时,默认情况下它将打开index.html,而不必将其放在地址栏中。

相关问题