express-breadcrumbs

0.0.2 • Public • Published

express-breadcrumbs

Easy to use generic breadcrumbs middleware for Express.

Install

npm install express-breadcrumbs --save

Usage

1 - Initialization

Intializes Breadcrumbs in server.js.

// server.js
 
var breadcrumbs = require('express-breadcrumbs');
app.use(breadcrumbs.init());
 
// Set Breadcrumbs home information
app.use(breadcrumbs.setHome());
 
// Mount the breadcrumbs at `/admin`
app.use('/admin', breadcrumbs.setHome({
  name: 'Dashboard',
  url: '/admin'
}));

2 - Adding breadcrumbs

Call req.breadcrumbs('name', 'url') on each request, and call req.breadcrumbs() to obtain data.

// routes.js
 
app.get('/signup', function(req, res) {
  req.breadcrumbs('SignUp');
  res.render('/signup', {
    breadcrumbs: req.breadcrumbs()
  });
});

More usages:

// one by one
req.breadcrumbs('name', 'url');
 
// object with properties `name` and `url`
req.breadcrumbs({
  name: 'name',
  url: 'url'
});
 
// objects with properties `name` and `url`
req.breadcrumbs([obj1, obj2]);

3 - Using in templates

To use breadcrumbs in template, only that you need is iterate over breadcrumbs.

// signup.jade

ul
  each breadcrumb in breadcrumbs
    li: a(href="#{breadcrumb.url}") #{breadcrumb.name}

Readme

Keywords

none

Package Sidebar

Install

npm i express-breadcrumbs

Weekly Downloads

244

Version

0.0.2

License

MIT

Last publish

Collaborators

  • heroicyang