Я пытаюсь передать в качестве параметра идентификатор элемента в детский список «Мой список».Видимо роутер может найти правильный путь, я попытался создать неправильные пути, чтобы прийти к такому выводу.в моей адресной строке отображается именно тот путь, который должен идти, хотя компонент не отображается, он даже не появляется в ngOnInit ().
Как показывает мой код.
Мой модуль маршрутизатора:
const clienteRoutes: Routes = [
{
path: '',
component: ClienteComponent,
children: [
{
path: '', redirectTo: 'listar'
},
{
path: 'adicionar', component: ClienteFormComponent,
},
{
path: 'listar', component: ClientesListComponent,
children: [
{
path: 'ver/:id',
component: ClienteFormComponent,
resolve: {
cliente: ClienteResolverService
}
}
]
},
]
}
];
Мой резольвер:
export class ClienteResolverService implements Resolve<Cliente> {
constructor(private cliente: ClienteService, private router: Router) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Cliente> |
Observable<never> {
const id = route.paramMap.get('id');
return this.cliente.buscarCliente(Number(id)).pipe(
take(1), mergeMap(cliente => {
if (cliente) {
console.log(cliente.clienteId);
return of(cliente);
} else {
this.router.navigate(['/adssadasdas/']);
return EMPTY;
}
})
);
}
}
Мой компонент списка:
this.listaClientes = this.route.paramMap.pipe(
switchMap(params => {
this.selectId = +params.get('id');
console.log(this.selectId);
return this.clienteService.listarClientes();
})
);
Мой компонент детализации:
export class ClienteFormComponent implements OnInit, OnDestroy {
ngOnInit() {
this.buildForm();
this.initCheckboxSubscription();
this.route.data.subscribe((data: { cliente: Cliente}) => {
console.log(data.cliente.nome);
});
}
}
Консоль: ![enter image description here](https://i.stack.imgur.com/EYcds.jpg)
dsa