Angular 角度2设置应用程序路由问题
我是新来的。我想在根URL()处显示“HomeComponent”,在根URL()处显示“PostsComponent”。我在app.routing.ts上设置了以下内容Angular 角度2设置应用程序路由问题,angular,Angular,我是新来的。我想在根URL()处显示“HomeComponent”,在根URL()处显示“PostsComponent”。我在app.routing.ts上设置了以下内容 export const AppRoutes: Routes = [ { path: '', component: AdminLayoutComponent, children: [{ path: '', component: HomeComponent }, {
export const AppRoutes: Routes = [
{
path: '',
component: AdminLayoutComponent,
children: [{
path: '',
component: HomeComponent
}, {
path: 'posts',
loadChildren: './posts/posts.module#PostsModule'
},{
path: '**',
component: PageNotFoundComponent
}]
}
];
主元件首次正确显示。当我访问posts URL(post组件也正确显示)并返回根URL(通过单击链接-例如:主页链接)时,它会显示“页面未找到组件”。但当我重新加载页面时,它正确地显示了主组件
我错过了什么
注意:如果我对“”(空)路径使用“redirectTo”选项,则它可以工作。然后主组件将显示在。但是我想在上显示主页组件,这是错误的URL
path: '',
component: AdminLayoutComponent,
children: [{
path: '',
component: HomeComponent
},
根据您的配置,这是HomeComponent所需的路由://”
试着做下一步
export const AppRoutes: Routes = [
{
path: '',
component: AdminLayoutComponent,
children: [{
path: 'home',
component: HomeComponent
}, {
path: 'posts',
loadChildren: './posts/posts.module#PostsModule'
},{
path: '**',
component: PageNotFoundComponent
}]
}
];
这是错误的URL
path: '',
component: AdminLayoutComponent,
children: [{
path: '',
component: HomeComponent
},
根据您的配置,这是HomeComponent所需的路由://”
试着做下一步
export const AppRoutes: Routes = [
{
path: '',
component: AdminLayoutComponent,
children: [{
path: 'home',
component: HomeComponent
}, {
path: 'posts',
loadChildren: './posts/posts.module#PostsModule'
},{
path: '**',
component: PageNotFoundComponent
}]
}
];
当您降落在主组件上时,它将重定向到空路径not/Home。所以试试下面的方法,它会有帮助的。它所做的是,只要找到空路径,它就会重定向到外部主组件。试着加上我在下面写的几行 >>>添加的代码从这里开始
当您降落在主组件上时,它将重定向到空路径not/Home。所以试试下面的方法,它会有帮助的。它所做的是,只要找到空路径,它就会重定向到外部主组件。试着加上我在下面写的几行 >>>添加的代码从这里开始
此配置显示的是位于的主组件,并且显示的是根目录的“未找到页面”。但是我想在roots上显示home组件,您导入了吗?从“/您的路径”导入{AdminLayoutComponent};此配置显示的是位于的主组件,并且显示的是根目录的“未找到页面”。但是我想在roots上显示home组件,您导入了吗?从“/您的路径”导入{AdminLayoutComponent};