【发布时间】:2020-01-14 17:45:26
【问题描述】:
我正在尝试在生产模式下构建我的 Angular 应用程序并遇到一个奇怪的错误。
在开发模式下一切正常。但是在生产模式下,当我打开“index.html”时,我会正确地重定向到我想要的默认路径,但我的 router-outlet 没有填充。
我的 app-routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { GraphMapComponent } from './graph-map/graph-map.component';
import { ZoneEditorComponent } from './zone-editor/zone-editor/zone-editor.component';
import { ZonesOverviewComponent } from './zone-editor/components/zones-overview/zones-overview.component';
import { ZoneConfigurationComponent } from './zone-editor/components/zone-configuration/zone-configuration.component';
import { NewZoneSelectionComponent } from './zone-editor/components/new-zone-selection/new-zone-selection.component';
const routes: Routes = [
{ path: '', redirectTo: '/zone-editor/zones', pathMatch: 'full' },
{
path: 'path-editor',
component: GraphMapComponent
},
{
path: 'zone-editor',
component: ZoneEditorComponent,
children: [
{
path: 'zones',
component: ZonesOverviewComponent,
data: { animation: 'isLeft' }
},
{
path: 'add-zone',
component: NewZoneSelectionComponent,
data: { animation: 'isRight' }
},
{
path: 'zone/:id',
component: ZoneConfigurationComponent,
data: { animation: 'isRight' }
},
{
path: '',
redirectTo: 'zones',
pathMatch: 'full'
}
]
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
我尝试了不同的方法,但我无法弄清楚。它在开发模式下工作。当我在ng serve 期间调用enableProdMode(); 时,它也有效。
只有当我使用 build --prod 并进行缩小/优化/等时它才不起作用。
任何帮助表示赞赏。我可以在必要时提供更多信息,但我不确定是哪一个。
【问题讨论】:
-
您解决了这个问题吗?你做了什么来解决它?我现在被这个问题困住了。
-
我遇到了这个问题,但我不知道为什么它不起作用。使用 ng serve 很好,但使用 ng build —prod 不起作用。有人有什么想法吗?
标签: angular angular-routing angular-router