npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-simple-breadcrumb

v17.0.3

Published

A tiny breadcrumb library for Angular. Under 40kb in size with no additional dependencies.

Downloads

1,099

Readme

NgxSimpleBreadcrumb

A tiny breadcrumb library for Angular. Under 40kb in size with no additional dependencies.

Add a breadcrumb to your Angular app in 5 minutes.

Versioning

| Version | Compatible Angular Version | |---------|----------------------------| | 17.x.x | >=17.0.0 | | 16.x.x | >=16.0.0 |

Quick Start

Installation

npm install ngx-simple-breadcrumb

Setup

Import NgxSimpleBreadcrumbModule in your app module.

app.module.ts

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { RouterModule } from '@angular/router';
import { NgxSimpleBreadcrumbModule } from 'ngx-simple-breadcrumb';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...
    NgxSimpleBreadcrumbModule,
    RouterModule.forRoot([
     ...
    ])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage Example

1. Add the nxg-simple -breadcrumb component

app.component.html

<ngx-simple-breadcrumb>
  <ng-template let-breadcrumb>
    <a [routerLink]="breadcrumb.route">{{breadcrumb.label}}</a>
  </ng-template>
  <ng-template #separator> > </ng-template>
</ngx-simple-breadcrumb>

<router-outlet />

The first template defines each breadcrumb item. It can access the breadcrumb object by using let-breadcrumb.

The breadcrumb object contains the following properties

  • label - as defined in the breadcrumb property of the route data object (see next step)
  • route - the full path which can be used to build a link (as seen in example)
  • isLast - whether or not the breadcrumb is the last in the trail

The second template defines the separator which will separate each breadcrumb item. It must be identified by the template reference variable #seperator.

These templates allow you the flexibility to add icons, images, styling etc. however you wish.

2. In your routing confing, add the breadcrumb property to the data object for each route you would like to appear in your breadcrumb.

This value will be made available in your template as breadcrumb.label.

app-routing.module.ts

[
  {
    path: 'child1',
    component: Child1Component,
    data: {breadcrumb: 'Child 1'},
    children:
    [{
      path: 'grandchild1',
      component: Grandchild1Component,
      data: { breadcrumb: 'Grandchild 1' },
    }]
  },
  {
    path: 'child2',
    component: Child2Component,
    data: {breadcrumb: 'Child 2'},
  }
]

Troubleshooting

Duplicate Breadcrumbs

Note the Angular behaviour that an empty path route inherits its parent's parameters and data.

This means if you add a breadcrumb to an empty path route (such as is common when lazy loading a module), its children will also inherit this breadcrumb and create duplicates. This can be avoided by only adding the breadcrumb data property to the children of empty path routes.