4

I'd like to show Breadcrumbs for my pages in express. I couldn't find much and it seems like there are only a few people who want to build breadcrumbs on their websites or there must be a completely different way to solve the issue. I found 2-3 middlewares which are not actively maintained and it seems they doesn't support dynamic routes or it's not documentated well.

So assuming I got the following routes and breadcrumb names:

  • / => "Home"
  • /projects => "Projects"
  • /projects/:id/:slug => "Projectname from DB"
  • /projects/manage => "Manage"

I expected a popular middleware which is capable of storing breadcrumbs dynamically and once I call a "subpage" it will list return all parent breadcrumbs too. Something like this:

router.get('/:id/:slug', function(req, res, next) {
    var projectName = 'John Doe Project';
    req.breadcrumbs().add({name: projectName, url: '/url/to/project/'});
    res.render('projects/index', { title: 'Express', breadcrumbs: req.breadcrumbs()});
});

What is the best practice for providing breadcrumbs?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
kentor
  • 16,553
  • 20
  • 86
  • 144
  • What was wrong with https://www.npmjs.com/package/express-breadcrumbs – hjpotter92 May 02 '17 at 17:08
  • @hjpotter92 it didn't add the parent's breadcrumbs automatically. I am not sure if it's supposed to do so, but it seems like I need to add all the desired breadcrumbs for each route manually. – kentor May 02 '17 at 17:13
  • Is there a reason can't you parse the route yourself and render crumbs based on the parts? – Ezra Chang May 02 '17 at 17:42
  • Well I could, but 1. I don't want add all URL parts into my breadcrumb and 2. Each part should have a breadcrumb name. Hence I thought I'd rather ask how others are handling breadcrumbs – kentor May 02 '17 at 17:52

0 Answers0