Tuesday, 2 May 2017

Breadcrumbs Express

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?



via kentor

No comments:

Post a Comment