Angular 如何避免“;404-未找到文件或目录;在URL中引用路由链接时
如何避免“404-找不到文件或目录”。在中引用路由链接时 例如,如果导航到某个页面,则会显示此URL:Angular 如何避免“;404-未找到文件或目录;在URL中引用路由链接时,angular,iis,Angular,Iis,如何避免“404-找不到文件或目录”。在中引用路由链接时 例如,如果导航到某个页面,则会显示此URL: http://www.semiwebs.com/angular-semi/sagesoftware 它是有效的。但是如果您自己在浏览器中键入此URL,则会出现错误 404-找不到文件或目录 在使用localhost的开发机器上,通过网站的导航和http://localhost:4200/sagesoftware也可以使用 我缺少什么设置来阻止服务器上的导航?IIS7是一个在客户端处理路由的单
http://www.semiwebs.com/angular-semi/sagesoftware
它是有效的。但是如果您自己在浏览器中键入此URL,则会出现错误
404-找不到文件或目录
在使用localhost的开发机器上,通过网站的导航和http://localhost:4200/sagesoftware
也可以使用
我缺少什么设置来阻止服务器上的导航?IIS7是一个在客户端处理路由的单页应用程序。您需要在服务器上添加
rewrite
规则,将所有路由重定向到index.html
页面
发生的情况是服务器正在尝试查找路径http://www.semiwebs.com/angular-semi/sagesoftware
这是不存在的。您需要将其传递到index.html
以便知道显示哪个组件
我在网上找到的一个例子:
web.config
<rewrite>
<rules>
<rule name="SPA Routes" stopProcessing="true">
<!-- match everything by default -->
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<!-- unless its a file -->
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<!-- or a directory -->
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<!-- or is under the /api directory -->
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
<!-- list other routes or route prefixes here if you need to handle them server side -->
</conditions>
<!-- rewrite it to /index.html -->
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
SPA的规则是在客户端处理路由的单页应用程序。您需要在服务器上添加rewrite
规则,将所有路由重定向到index.html
页面
发生的情况是服务器正在尝试查找路径http://www.semiwebs.com/angular-semi/sagesoftware
这是不存在的。您需要将其传递到index.html
以便知道显示哪个组件
我在网上找到的一个例子:
web.config
<rewrite>
<rules>
<rule name="SPA Routes" stopProcessing="true">
<!-- match everything by default -->
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<!-- unless its a file -->
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<!-- or a directory -->
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<!-- or is under the /api directory -->
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
<!-- list other routes or route prefixes here if you need to handle them server side -->
</conditions>
<!-- rewrite it to /index.html -->
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
SPA的规则这看起来应该有效,但我应该把规则放在哪里?我尝试了index.html的底部,但没有成功。我仍在试图找到绕过角度框架的方法。感谢放置在web.config
文件中的内容,该文件应位于项目的根目录下。这并不是angular特有的,它更多地是关于如何配置web服务器的。我将web.config文件放在angular ssi的根目录中。现在,当我输入URL时,它显示为,并返回一个500内部服务器错误。您正在查找的资源有问题,无法显示。我仍然缺少一些东西。我使用了上面相同的web.config,但已删除到“条件”部分。两种方法都试过。试一下这个看起来应该有效,但是我该把规则放在哪里呢?我尝试了index.html的底部,但没有成功。我仍在试图找到绕过角度框架的方法。感谢放置在web.config
文件中的内容,该文件应位于项目的根目录下。这并不是angular特有的,它更多地是关于如何配置web服务器的。我将web.config文件放在angular ssi的根目录中。现在,当我输入URL时,它显示为,并返回一个500内部服务器错误。您正在查找的资源有问题,无法显示。我仍然缺少一些东西。我使用了上面相同的web.config,但已删除到“条件”部分。两种方法都试过,试试这个