该问题与Angular 8有关。
我有一个在IIS上运行的网站,其代码在. Net和AngularJs 1.6中显示为www.parent.com
And I am building a completely new website in pure Angular 8 (single page application), currently having some of the pages of www.parent.com project. Also I have to run them both on the same domain. So I am trying to host the new website in a virtual directory.
我尝试的是:
1.创建了虚拟目录,例如**/v2**
1.使用ng build --base-href "/v2" --deploy-url "/v2/"
构建Angular8项目,并将dist复制到**/v2目录中
1.尝试访问www. parent. com/v2/**
一切都运行良好,导航到不同的页面等。路由在Angular8项目上运行良好,例如-www. parent. com/v2/timestule、www. parent. com/v2/noticeboard
但当我在其中一个页面从子项目和刷新页面它给出了以下错误
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.
Things you can try:
Create the content on the Web server.
Review the browser URL.
Create a tracing rule to track failed requests for this HTTP status code and see which module is calling SetStatus. For more information about creating a tracing rule for failed requests, click here.
Detailed Error Information:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://parent.com:80/Child/timetable/worker
Physical Path D:\WebSites\Child\timetable\worker
Logon Method Anonymous
Logon User Anonymous
更新:
1.按此添加web. config
1.在angular 8项目的index.html中添加
目录结构:
C:\web\项目\父级-〉. net项目
C:\web\v2-〉Angular 8项目
IIS中名为v2的虚拟目录指向C:\web\v2
- C:\网页\v2\源代码\网页配置**:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="true" />
<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="/v2" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
1条答案
按热度按时间nx7onnlm1#
任何人谁有这个问题在这个时候。
加入溶液:
到NgModule部分中的app.module.ts。如下所示:
重建你的项目。
别忘了用途:
您可以在https://angular.io/api/common/APP_BASE_HREF上看到此示例
祝您玩得愉快!