【发布时间】:2020-05-24 08:14:08
【问题描述】:
在我将另一个组件声明放入我的 shop.module.ts 和 shop.routing.ts 之前,我的 angular 8 应用程序很好
我的app.routing.ts
export const AppRoutes: Routes = [
{
path: '',
redirectTo: 'shop',
pathMatch: 'full',
},
{
path: '',
component: FrontendPanelLayoutComponent,
children: [
{
path: 'shop',
loadChildren: './shop/shop.module#ShopModule'
}
]
}
];
我的shop.module.ts
@NgModule({
imports: [
CommonModule,
GlobalModule,
SlickModule.forRoot(),
NouisliderModule,
AgmCoreModule.forRoot({apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'}),
RouterModule.forChild(ShopRoutes),
],
declarations: [
ShopListingComponent,
ShopDetailComponent //I newly put this one.
],
providers: [
ShopService
]
})
export class ShopModule { }
我的shop.routing.ts
export const ShopRoutes: Routes = [
{
path: '',
component: ShopListingComponent
},
//I newly put this one.
{
path: 'shop/detail',
component: ShopDetailComponent
}
];
当我从 shop.module.ts 和 shop.routing.ts 中删除 ShopDetailComponent 时,我的应用程序完全正常。当我再次输入 ShopDetailComponent 时,应用程序正在以空白页面运行而没有错误。我的路由声明有问题吗?
【问题讨论】:
-
将
path: 'shop/detail'更改为path: 'detail'并尝试。前缀shop已经存在于app.routing.ts中 - 您无需在shop.routing.t中重复它
标签: angular typescript routing angular8