Open tomrainedotcom opened 6 years ago
I have exactly the same problem... I imagine it's related how it's handled this._resolveCrumbs(route) in mc-breadcrumbs.service but I'm not very familiar with this.
Better approach here is to use resolver to retrieve data and store in route data. Then use the route information to build breadcrums like normal ( because now in route data you have the unitName ) . UnitResolver
@Injectable()
export class UnitResolver implements Resolve<Observable<boolean>> {
constructor(private eventsService: EventsService) { }
public resolve(route: ActivatedRouteSnapshot): Observable<string> {
return new Observable<string>((observer) => {
// Your old code , just put it back here
this.eventsService.getEvent(route.params.id || route.parent.params.id).subscribe((event) => {
event.courses.forEach((course) => {
if (course !== null) {
let unitName = '';
const foundUnit = course.units.find((unit) => {
return unit.id === (route.params.unitId || route.parent.params.unitId);
});
if (foundUnit) {
unitName = foundUnit.name;
observer.next(unitname);
observer.complete();
}
// TODO: Handle case if not found the unit here ?
}
});
});
});
}
}
some routing example :
{
path: 'overview',
component: OverviewComponent,
data: {title: 'Event Overview', breadcrumbs: BreadcrumbResolver},
resolve : {
unitName: UnitResolver ,
}
}
Usage in BreadcrumbsResolver
const unitName= routeSnapshot.data.unitName;
breadCrumbs.push({
text: unitName,
path: this.router.createUrlTree(['events', event._id]).toString()
});
Can anyone help me out here? I have a custom Breadcrumb resolver to get names of events and there units from dynamic data, logging shows the array of breadcrumbs is compiled correctly but I only get a "1." displayed where the breadcrumb is supposed to be.
Is the following the correct way to return Observable<IBreadcrumb[]>?
I am using Angular 6 and have used the git repo and built out the Angular 6 converted version.
BreadcrumbResolver
Routing Module
Logged breadcrumbs
How it looks in the DOM