Angular 角度路由器。从父组件到子组件导航不工作
在我的例子中,我成功地从availableComponent导航到-->reserveComponent。但当我尝试导航到confirmComponent时,riuter.navigate不起作用 我尝试通过以下代码重定向到confirmComponent:Angular 角度路由器。从父组件到子组件导航不工作,angular,angular-material,angular-ui-router,router,Angular,Angular Material,Angular Ui Router,Router,在我的例子中,我成功地从availableComponent导航到-->reserveComponent。但当我尝试导航到confirmComponent时,riuter.navigate不起作用 我尝试通过以下代码重定向到confirmComponent: onContinuePayment() { // this.router.navigated = false; debugger this.router.navigate(['flight/confirm'], {
onContinuePayment() {
// this.router.navigated = false;
debugger
this.router.navigate(['flight/confirm'], {
queryParams: {
source: 'g'
}
});
}
我的路由模块是:
const routes: Routes = [
{
path: '' , component: FlightComponent,
children: [
{
path: 'available',
component: AvailableFlightsComponent
} ,
{
path: 'reserve',
component: ReserveFlightComponent
} ,
{
path: 'confirm',
component: ReserveConfirmComponent
} ,
{
path: 'reserve-confirm',
component: ReserveConfirmationComponent
}
]
}];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
但它不起作用
path: '' , component: FlightComponent
应该是
path: 'flight' , component: FlightComponent
这里您的目的是为URL设置路由,其中{child}
是可用的,保留的,确认的,等等
假设您还希望为url/flight
提供航班组件,则将路径flight
分配给父航线将意味着子航线将有效地继承其路径的/flight/
前缀
如果您不希望航班组件与url/flight
关联,则可以在航班及其子项之间插入无组件路由:
const routes: Routes = [
{
path: '' , component: FlightComponent,
children: [
{ path: 'flight', children: [
{
path: 'available',
component: AvailableFlightsComponent
} ,
{
path: 'reserve',
component: ReserveFlightComponent
} ,
{
path: 'confirm',
component: ReserveConfirmComponent
} ,
{
path: 'reserve-confirm',
component: ReserveConfirmationComponent
}
] }
]
}];
你应该使用
this.router.navigate(['/flight/confirm'], {
queryParams: {
source: 'g'
}
});
问候。请试试这一款
this.router.navigate(['confirm'], {
queryParams: {
source: 'g'
}
});
如果父路由配置了路径“flight”,router.navigate将很乐意使用['flight/confirm']
。@armandyjoe this.router.navigate(['/flight/confirm']无效您在哪里添加了路由器出口?路由器出口存在于flight组件中