Skip to content

Improvement: dynamic breadcrumb 'displayName' from Routing #17

@aalmajanob

Description

@aalmajanob

Hi emilol,

First of all, nice component, I´m currently using it within a real project and it works nice with just a few improvements.

I would like to propose the following improvement (Im at work and do not have much time to make a pull request):

  1. Just change the method createBreadcrumb() from here https://github.com/emilol/angular-crumbs/blob/master/src/breadcrumb.service.ts#L63 with the following:
    private createBreadcrumb(route: ActivatedRouteSnapshot, url: string): Breadcrumb {
        // Generates display text from data
        // -- Dynamic route params when ':[id]'
        let d = '';
        const split = route.data['breadcrumb'].split(' ');
        split.forEach((s: string) => {
            d += `${s.indexOf(':') > -1 ? (route.params[s.slice(1)] ? route.params[s.slice(1)] : '') : s} `;
        });
        d = d.slice(0, -1);

        return {
            displayName: d,
            terminal: this.isTerminal(route),
            url: url,
            route: route.routeConfig
        };
    }
  1. This way, now it is possible to customize more the displayName:
  • Static displayName (like now):
    { path: 'home', ... , data: { breadcrumb: 'Home' } }
  • Or a Dynamic displayName:
    { path: ':yearId/:monthId/:dayId', component: SubhomeComponent, data: { breadcrumb: 'SubHome with Year :id Month :monthId Day :dayId} }

Regards :)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions