Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当路由到子目录中的应用程序时,URL在Angular2中增长_Angular_Routing_Http Status Code 404 - Fatal编程技术网

当路由到子目录中的应用程序时,URL在Angular2中增长

当路由到子目录中的应用程序时,URL在Angular2中增长,angular,routing,http-status-code-404,Angular,Routing,Http Status Code 404,我的Angular2应用程序部署在IIS网站的子目录中。我使用以下命令来构建它。(-bh将子目录设置为应用程序的根目录): 然后我在应用程序中使用routing with,如下所示 app.routes.ts: import { Routes } from '@angular/router'; import { DnaPlotComponent } from './dna-plot/dna-plot.component'; export const routes: Routes = [{ pa

我的Angular2应用程序部署在IIS网站的子目录中。我使用以下命令来构建它。(-bh将子目录设置为应用程序的根目录):

然后我在应用程序中使用routing with,如下所示

app.routes.ts:

import { Routes } from '@angular/router';
import { DnaPlotComponent } from './dna-plot/dna-plot.component';

export const routes: Routes = [{ path: '', component: DnaPlotComponent }];
app.module.ts:

import { RouterModule } from '@angular/router';
import { routes } from './app.routes';
...
RouterModule.forRoot(routes)
每次刷新页面时,URL都会附加子目录。这意味着URL无限增长且无法刷新,导致404。这是我所看到的一个例子

https://develop.domain.com/dnaplot/dnaplot#/dnaplot/
名为的原始URL为:

https://develop.domain.com/dnaplot
任何阻止这种情况发生的想法都将不胜感激。

您需要设置
或提供指向已部署路径的
APP\u BASE\u HREF

有关更多详细信息,请参阅

提供
APP\u BASE\u HREF
通常是更好的方法,因为它只影响路由器,而
会影响SVG引用等其他内容

路径为空且没有子路由的路由应具有路径匹配:“已满”

export const routes:routes=[{path:'',组件:DnaPlotComponent,pathMatch:'full'}];

最终的解决方案只是将base href设置为空字符串,即。

路由器似乎“意识到”原始构建命令中的
--bh testdna
,因此无需在href标记中重新声明子目录

https://develop.domain.com/dnaplot