【发布时间】:2018-07-18 22:18:28
【问题描述】:
我的 Angular 4 应用程序作为 IIS 中的“应用程序”托管在“网站”内,比如说“MyApp”,我已经使用 angular-cli 使用以下命令生成了生产版本:
ng build --prod --base-href=/MyApp/
我还在 IIS 中配置了 Url 重写,下面是位于 index.html 旁边的 web.config 文件
<configuration>
<system.webServer>
<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" />
</conditions>
<action type="Rewrite" url="/MyApp/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
以下是我的主要应用程序路由,它基本上具有不同模块的入口点,并具有自己的路由:
@NgModule({
imports: [
RouterModule.forRoot([
{ path: 'vm', redirectTo: 'vm/vehicles', pathMatch: 'full' },
{ path: 'rp', redirectTo: 'rp/gantt', pathMatch: 'full' },
{ path: '', redirectTo: 'rp/gantt', pathMatch: 'full' },
{ path: '404', component: PageNotFoundComponent },
{ path: '**', redirectTo: '404' }
]
)
],
exports: [
RouterModule
]
})
export class AppRoutingModule { }
问题是,如果我使用此 URL http://localhost:8181/MyApp/vm 访问应用程序,应用程序加载正常,但必须呈现针对 vm/vehicles 配置的组件的 <router-outlet></router-outlet> 不会加载,它在 @ 内显示 404 组件987654330@ 和 url 更改为 http://localhost:8181/MyApp/404。
以下是vm模块的路由:
const moduleName = 'vm';
const routes: Route[] = [
{ path: 'vehicles', component: VehicleComponent },
{ path: 'standards', component: StandardsComponent }
];
routes.forEach((item) => {
item.path = moduleName + '/' + item.path;
});
@NgModule({
imports: [
RouterModule.forChild(routes)
],
exports: [
RouterModule
]
})
export class VehicleRoutingModule { }
【问题讨论】:
-
在开发模式下对你有用吗
标签: angular routing angular4-router