【发布时间】:2019-05-06 14:48:36
【问题描述】:
我正在尝试根据父子概念导航我的 Angular 应用程序。 当我加载父组件而不是子组件时,但 url 似乎是
const appRoute: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'dashboard', component: DashboardComponent },
{
path: 'solutions', component: SolutionComponent,
children: [
{ path: 'cog', component: CogComponent }
]
},
{ path: 'portfolio', component: PortfolioComponent },
{ path: '**', component: PortfolioComponent }
];
当我运行solutions/cog 时,它会重定向到SolutionComponent,但它应该加载CogComponent
编辑:1
当我使用时它会起作用
const appRoute: Routes = [
{ path: 'home', component: HomeComponent },
{ path: 'dashboard', component: DashboardComponent },
{ path: 'solutions', component: SolutionComponent },
{ path: 'solutions/cog', component: CogComponent },
{ path: 'portfolio', component: PortfolioComponent },
{ path: '**', component: PortfolioComponent }
];
但我希望它应该从上述方法加载。
请帮忙解决这个问题。
【问题讨论】:
-
它没有重定向到
SolutionComponent。它按预期工作。按照您配置路由的方式,SolutionComponent在 HTML 中应该有一个<router-outlet>。然后,如果您导航到solutions/cog,它将显示SolutionComponent和CogComponent代替router-outlet。
标签: angular angular-ui-router angular4-router