【发布时间】:2017-03-13 14:04:52
【问题描述】:
我是 Angular 2 的新手。我想在根 URL (http://localhost:4200) 上显示“HomeComponent”,在http://localhost:4200/posts 上显示“PostsComponent”。我在 app.routing.ts 设置了以下内容。
export const AppRoutes: Routes = [
{
path: '',
component: AdminLayoutComponent,
children: [{
path: '',
component: HomeComponent
}, {
path: 'posts',
loadChildren: './posts/posts.module#PostsModule'
},{
path: '**',
component: PageNotFoundComponent
}]
}
];
Home 组件第一次正确显示。当我访问帖子 URL(帖子组件也正确显示)并返回根 URL(通过单击链接 - 例如:主页链接)时,它显示“页面未找到组件”。但是当我重新加载页面时,它会正确显示主页组件。
我在这里错过了什么?
注意:如果我对“”(空)路径使用“redirectTo”选项,那么它正在工作。然后主页组件将显示在http://localhost:4200/home。但我想在 http://localhost:4200 显示 home 组件
【问题讨论】:
标签: angular