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

pp-breadcrumbs

v2.0.0

Published

PP-Breadcrumbs is an Angular 10 library generating breadcrumbs based on the routing state.

Downloads

218

Readme

PP-Breadcrumbs

PP-Breadcrumbs is an Angular 10 library generating breadcrumbs based on the routing state.

Demo: Stackblitz

Installation

Install via npm:

npm install pp-breadcrumbs --save 

Once you installed, you need to import the module:

import { PpBreadcrumbsModule } from 'pp-breadcrumbs';

@NgModule({
  ...
  imports: [PpBreadcrumbsModule, ...],
  ...
})
export class AppModule {
}

Usage

Use the pp-breadcrumbs component to render the breadcrumbs:

@Component({
  selector: 'app-root',
  template: `
    <div class="container">
      <pp-breadcrumbs></pp-breadcrumbs>
      <router-outlet></router-outlet>
    </div>`
})
export class AppComponent {}

Rendering with pp-breadcrumbs is optional, and uses Bootstrap 4 CSS classes. If a different markup output is desired, a custom component can be created that subscribes to the PpBreadcrumbsService.crumbs$ observable.

Routing Configuration

Breadcrumb links are generated based on the route configuration. If a route entry contains a data.breadcrumbs property the breadcrumbs service assumes breadcrumbs should be created whenever this route or one its child routes are active.

const routes: Routes = [
  {
    path: 'items',
    // Uses static text (Items)
    data: { breadcrumbs: 'Items' },
    children: [
      { path: '', component: ListComponent },
      {
        path: ':id',
        // Interpolates values resolved by the router
        data: { breadcrumbs: '{{ item.name }}' },
        resolve: { item: ItemResolver },
        children: [
          { path: '', component: ItemComponent },
          { path: 'subitem', component: SubitemComponent, data: { breadcrumbs: `<i class="fas fa-user"></i> Subitem` } }
        ]
      }
    ]
  },
  {
    path: 'another-items',
    // Uses last urlfragment (another-items) as text
    data: { breadcrumbs: true },
    children: [
      { path: '', component: ListComponent },
      {
        path: ':id',
        // Resolves the breadcrumbs for this route by extending the PpBreadcrumbsResolver class.
        data: { breadcrumbs: AnotherItemResolver },
        children: [
          { path: '', component: ItemComponent },
          { path: 'subitem', component: SubitemComponent, data: { breadcrumbs: 'Subitem' } }
        ]
      }
    ]
  },
];

API reference

Breadcrumb

Represents a breadcrumb. HTML content in the text property is allowed.

export interface Breadcrumb {
  text: string;
  path: string;
}

PpBreadcrumbsComponent

Selector: [pp-breadcrumbs]

Renders the Breadcrumb[] provided by the PpBreadcrumbsService. The HTML output is based on the Bootstrap 4 breadcrumbs.

Properties

| Name | Description | | --- | --- | | crumbs: Breadcrumb[] | Actually rendered breadcrumbs |

PpBreadcrumbsService

Properties

| Name | Description | | --- | --- | | crumbs$: Observable<Breadcrumb[]> | Observable stream of Breadcrumb[], which is updated after each route change | | postProcess: (crumbs: Breadcrumb[]) => Promise<Breadcrumb[]> | Observable<Breadcrumb[]> | Breadcrumb[] | Callback function, which allows to modify the fully created breadcrumbs |

PpBreadcrumbsResolver

Resolving Breadcrumb[] from the route, PpBreadcrumbsService uses this resolver by default. There are two ways to resolve breadcrumbs:

  • use a resolver, which implements the Resolve<T> (regular resolver), and use like this:
    const routes: Routes = [
      ..
      { path: ':id', data: { breadcrumbs: '{{ item.name }}' }, resolve: { item: ItemResolver } },
      ..
    ];
  • use a resolver, which extends from PpBreadcrumbsResolver and return the created breadcrumb. Then use like this:
    const routes: Routes = [
      ..
      { path: ':id', data: { breadcrumbs: AnotherItemResolver } },
      ..
    ];

You can see examples for both ways in the demo app.

Methods

| Name | Description | | --- | --- | | resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Breadcrumb[]> | Promise<Breadcrumb[]> | Breadcrumb[] | Resolve function to create custom breadcrumbs for the given routes | | getFullPath(route: ActivatedRouteSnapshot): string | Returns the full path for the provided route snapshot |