An open API service indexing awesome lists of open source software.

https://github.com/henczi/ngx-crumbs

An ultimate breadcrumbs service for Angular.
https://github.com/henczi/ngx-crumbs

angular breadcrumb breadcrumbs ng ngx-crumbs

Last synced: about 2 months ago
JSON representation

An ultimate breadcrumbs service for Angular.

Awesome Lists containing this project

README

        

# NgxCrumbs

An ultimate breadcrumbs service for Angular.

Demo on [StackBlitz](https://stackblitz.com/edit/ngx-crumbs-demo)
## Getting started
### Install via NPM
```
npm i ngx-crumbs
```
### Import the `NgxCrumbsModule`
```ts
@NgModule({
/* ... */
imports: [
/* ... */
NgxCrumbsModule,
],
})

export class AppModule { }
```

## Usage

Use the `ngx-crumbs` component to display the breadcrumbs

```html

```

> You can create a full custom look by using the `NgxCrumbsService.crumbs$` observable

### Defining crumbs in Routes
```ts
// app-routing.module.ts
const routes: Routes = [
{
path: '',
data: { crumb: 'Home' }
/* component: ... */
},
{
path: 'profile',
data: { crumb: 'Profile' },
/* component: ... */
children: [
path: 'settings',
data: { crumb: 'Settings' },
/* component: ... */
]
}
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
```

### Defining crumbs in a component

```html

```

## Configuring

|parameter|default|description|
|--|--|--|
|noLink|false|true, if the crumb should not point to a path|
|link|undefined||

### Dynamic crumb text

If your breadcrumb depends on dynamic data, you can also pass a function to the `crumb` (or `crumb.text`). This function receives an object containing three fields - `data`, `params` and `queryParams`.

```ts
const routes: Routes = [
{ path: '...', data: { crumb: ({ data, params, queryParams }) => `...` } },
/* OR */
{
path: '...',
data: {
crumb: {
text: ({ data, params, queryParams }) => `...` }
}
},
}
];
```

In a component you can data-bind all available variables.

```html

```

### Override default link
```ts
const routes: Routes = [
{
path: 'post/:id',
resolve: { post: PostResolver },
data: {
crumb: [
{ text: 'Posts', link: '/posts' },
{ text: ({ data }) => `${data.post.name}` },
]
},
component: PostComponent
}
];
```

```html


```

### Multiple crumbs per component

```ts
const routes: Routes = [
{ path: 'posts', data: { crumb: 'Posts' } },
{
path: 'post/:id',
data: {
crumb: [
{ text: 'Posts', link: '/posts' },
{ text: ({ params }) => `Post: ${params.id}` },
]
},
/* component: ... */
}
];
```

```html



```

## Document title

```ts
export class AppComponent {

constructor(public crumbsService: NgxCrumbsService) {
crumbsService.crumbs$.subscribe(x => document.title = x.length
? `${x[x.length-1].text} | Demo`
: 'Demo'
)
}

}
```